package jnpf.attendance.service.handle.notice;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import jnpf.constants.AttendanceConstant;
import jnpf.enums.attendance.NoticeModuleEnum;
import jnpf.enums.attendance.UserSettingEnum;
import jnpf.model.attendance.dto.LineDrawingPeriodDto;
import jnpf.model.attendance.model.JumpUrl;
import jnpf.model.attendance.model.LineShiftChangeNoticeModel;
import jnpf.model.attendance.model.SystemNoticeStrategy;
import jnpf.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static jnpf.constants.AttendanceConstant.*;

@Component(AttendanceConstant.LINE_SHIFT_NOT_SCHEDUING)
@Slf4j
public class LineNotSchedulingAttendanceNotice implements AttendanceNotice<LineDrawingPeriodDto, LineShiftChangeNoticeModel> {
    @Autowired
    private AttendanceNoticeHandler attendanceNoticeHandler;

    @Override
    public Boolean isPass(LineShiftChangeNoticeModel attendanceNoticeModel) {
        return true;
    }

    @Override
    public List<LineDrawingPeriodDto> generatingData(LineShiftChangeNoticeModel attendanceNoticeModel) {
        //查询时段数据
        return attendanceNoticeModel.getPeriods();
    }

    @Override
    public List<String> getRecipient(LineShiftChangeNoticeModel attendanceNoticeModel) {
        return attendanceNoticeModel.getUserIds().stream().filter(userId -> attendanceNoticeHandler.checkBeforeCondition(userId, UserSettingEnum.ATTENDANCE_SETTING_MESSAGE_RECEIVE)).collect(Collectors.toList());
    }

    @Override
    public SystemNoticeStrategy setSystemNoticeStrategy(LineShiftChangeNoticeModel attendanceNoticeModel, String noticeId) {
        ArrayList<JumpUrl> objects = CollUtil.newArrayList();
        objects.add(JumpUrl.builder().url(String.format(BTN_LINE_SCHEDULE_URL, JSON.toJSONString(attendanceNoticeModel.getAttendanceGroup())) + "&moduleId=" + attendanceNoticeModel.getModuleId()).urlName(BTN_SCHEDULE_GO).color(COLOR_BLACK).build());
        return SystemNoticeStrategy.builder()
                .title(ATTENDANCE_NOTICE_LINE_SCHEDULED_TITLE)
                .noticeModuleEnum(NoticeModuleEnum.BC_BD)
                .jumpUrls(objects)
                .build();
    }

    @Override
    public String getContext(List<LineDrawingPeriodDto> data) {
        return "提醒通知：请您及时为划线排班人员排班！如已排班，请忽略";
    }

}
