package com.yida.data.attendance.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.common.core.entity.attendance.EduAttendanceRule;
import com.yida.data.common.core.entity.attendance.EduAttendanceRuleDate;
import com.yida.data.common.core.entity.attendance.EduAttendanceRuleTime;
import com.yida.data.attendance.vo.ConflictRuleVO;
import com.yida.data.attendance.vo.RuleListVO;

import java.time.LocalDate;
import java.util.List;

import org.apache.ibatis.annotations.Param;

public interface EduAttendanceRuleMapper extends BaseMapper<EduAttendanceRule> {

    IPage<RuleListVO> listRulePage(
            Page page,
            @Param("schoolId") Long schoolId,
            @Param("campusId") Long campusId,
            @Param("ruleName") String ruleName,
            @Param("type") Integer type,
            @Param("status") Integer status,
            @Param("startDate") String startDate,
            @Param("endDate") String endDate);

    List<ConflictRuleVO> checkNormalRule(@Param("deptIds") List<Long> deptIds,
                                         @Param("date") List<EduAttendanceRuleDate> date,
                                         @Param("time") List<EduAttendanceRuleTime> time,
                                         @Param("type") Integer type,
                                         @Param("ruleId") Long ruleId);

    List<RuleListVO> listValidRule(@Param("deptIds") List<Long> deptIds,
                                   @Param("date") LocalDate date,
                                   @Param("dayOfWeek") Integer dayOfWeek,
                                   @Param("type") Integer type,
                                   @Param("deviceSn") String deviceSn,
                                   @Param("schoolId") Long schoolId);

    void updateRuleStatus(@Param("now") LocalDate now,
                          @Param("status") Integer status);

    /**
     * 查询到期的规则
     *
     * @param now
     * @return
     */
    List<Long> listExpireRule(@Param("now") LocalDate now);

    /**
     * 查询将要启动的规则
     *
     * @param now
     * @return
     */
    List<Long> listNotStartRule(@Param("now") LocalDate now);

    /**
     * 查询当前时间段将要过期，下一段时间段未到的规则
     */
    List<Long> listWillStartRule(@Param("now") LocalDate now);

}