package com.base.plan.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.plan.model.dto.StepWindowDTO;
import com.base.plan.model.entity.AlgSchemeWindowPass;
import com.base.plan.model.entity.StepWindowDataPassRelation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;


@Mapper
@Repository
public interface StepWindowDataPassRelationMapper extends BaseMapper<StepWindowDataPassRelation> {

    List<StepWindowDTO> selectIsUsedStepStationWindowDTOList(@Param("list") List<String> list, @Param("isConfirm") Integer isConfirm);

    default void deleteByStepIds(List<String> list) {
        this.delete(new QueryWrapper<StepWindowDataPassRelation>().in("step_id", list));
    }

    void batchInsert(@Param("list") List<StepWindowDataPassRelation> list);

    default List<StepWindowDataPassRelation> selectByWindowId(Set<String> list) {
        return this.selectList(new QueryWrapper<StepWindowDataPassRelation>().in("window_id", list).eq("is_confirm", 2));
    }

    default void confirmWindow(List<String> list) {
        this.update(null, new UpdateWrapper<StepWindowDataPassRelation>().set("is_confirm", 1).in("step_id", list));
    }

    default void validateWindow(AlgSchemeWindowPass algSchemeWindowPass) {
        //  .get().getId(),optionalDataAlgSchemeWindowPass.get().getSchemeStepWindowId()
        this.update(null, new UpdateWrapper<StepWindowDataPassRelation>().set("is_confirm", 1).eq("data_station_window_id", algSchemeWindowPass.getId()).eq("window_id", algSchemeWindowPass.getSchemeStepWindowId()));
    }
}
