package com.cool.store.dao;

import com.cool.store.dto.interview.LineInterviewPageDTO;
import com.cool.store.entity.LineInterviewDO;
import com.cool.store.enums.InterviewStatusEnum;
import com.cool.store.enums.InterviewTypeEnum;
import com.cool.store.mapper.LineInterviewMapper;
import com.cool.store.request.LineInterviewPageRequest;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @FileName: LineInterviewDAO
 * @Description:
 * @date 2024-03-15 16:01
 */
@Repository
public class LineInterviewDAO {

    @Resource
    private LineInterviewMapper lineInterviewMapper;

    public LineInterviewDO getInterviewInfo(Long lineId, InterviewTypeEnum interviewType){
        if(Objects.isNull(lineId) || Objects.isNull(interviewType)){
            return null;
        }
        return lineInterviewMapper.getInterviewInfo(lineId, interviewType.getCode());
    }

    public List<LineInterviewDO> getInterviewByLindIds(List<Long> lineIds, InterviewTypeEnum interviewType){
        if(CollectionUtils.isEmpty(lineIds) || Objects.isNull(interviewType)){
            return Lists.newArrayList();
        }
        return lineInterviewMapper.getInterviewByLindIds(lineIds, interviewType.getCode());
    }

    public Integer updateInterviewInfo(LineInterviewDO interview){
        return lineInterviewMapper.updateByPrimaryKeySelective(interview);
    }

    public Long addInterviewInfo(LineInterviewDO interview){
        lineInterviewMapper.insertSelective(interview);
        return interview.getId();
    }

    /**
     * 获取面试分页列表
     * @param request
     * @return
     */
    public Page<LineInterviewPageDTO> getInterviewerPage(LineInterviewPageRequest request){
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        return lineInterviewMapper.getInterviewerPage(request);
    }

    /**
     * 获取面试信息
     * @param interviewId
     * @return
     */
    public LineInterviewDO getInterviewInfoById(Long interviewId){
        return lineInterviewMapper.selectByPrimaryKey(interviewId);
    }

    public LineInterviewDO getInterviewInfoByRoomId(String roomId){
        return lineInterviewMapper.getInterviewInfoByRoomId(roomId);
    }

    public Integer deleteInterviewInfo(Long interviewId) {
        return lineInterviewMapper.deleteInterviewInfo(interviewId);
    }

    public List<LineInterviewDO> getInterviewByLineId(Long lineId){
        return lineInterviewMapper.getInterviewByLineId(lineId);
    }

    public List<LineInterviewDO> getWaitAuditInterview(){
        return lineInterviewMapper.getWaitAuditInterview();
    }

    public Integer batchUpdateInterviewStatus(List<Long> interviewIds, InterviewStatusEnum interviewStatus) {
        if(CollectionUtils.isEmpty(interviewIds) || Objects.isNull(interviewIds)){
            return null;
        }
        return lineInterviewMapper.batchUpdateInterviewStatus(interviewIds, interviewStatus.getCode());
    }

    /**
     * 获取面试提醒列表
     * @param intervalMinutes
     * @return
     */
    public List<LineInterviewDO> getInterviewRemindList(String startTime, String endTime) {
        return lineInterviewMapper.getInterviewRemindList(startTime, endTime);
    }
}
