package jnpf.attendance.service.handle.notice;

import cn.hutool.core.collection.CollUtil;
import jnpf.constants.AttendanceConstant;
import jnpf.enums.attendance.NoticeModuleEnum;
import jnpf.enums.attendance.UserSettingEnum;
import jnpf.model.attendance.model.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 连续缺勤消息
 *
 * @author yanwenfu
 * @create 2024-08-12
 */
@Service(value = AttendanceConstant.CONSECUTIVE_ABSENCE)
public class ConsecutiveAbsenceNotice implements AttendanceNotice<ConsecutiveAbsenceModel, ConsecutiveAbsenceNoticeModel> {

    @Override
    public Boolean isPass(ConsecutiveAbsenceNoticeModel model) {
        return Boolean.TRUE;
    }

    @Override
    public List<ConsecutiveAbsenceModel> generatingData(ConsecutiveAbsenceNoticeModel model) {

        ConsecutiveAbsenceModel consecutiveAbsenceModel = ConsecutiveAbsenceModel.builder()
                .groupName(model.getGroupName())
                .userName(model.getUserName())
                .absenceDate(model.getAbsenceDate())
                .absenceDetailModel(model.getAbsenceDetailModel())
                .build();
        return List.of(consecutiveAbsenceModel);
    }

    @Override
    public List<String> getRecipient(ConsecutiveAbsenceNoticeModel attendanceNoticeModel) {

        return attendanceNoticeModel.getToUserList();
    }

    @Override
    public SystemNoticeStrategy setSystemNoticeStrategy(ConsecutiveAbsenceNoticeModel model, String noticeId) {

        List<JumpUrl> list = new ArrayList<>();
        list.add(new JumpUrl(String.format(AttendanceConstant.BTN_CONSECUTIVE_ABSENCE_URL, noticeId), AttendanceConstant.BTN_NAME_TO_DETAIL, AttendanceConstant.COLOR_BLACK));
        list.add(new JumpUrl(String.format(AttendanceConstant.ADMINISTRATOR_CHANGE_URL2, model.getGroupId()), AttendanceConstant.ADMINISTRATOR_CHANGE_BUTTON_NAME2, AttendanceConstant.COLOR_BLUE));

        return SystemNoticeStrategy.builder()
                .title(AttendanceConstant.TITLE_CONSECUTIVE_ABSENCE)
                .noticeModuleEnum(NoticeModuleEnum.KQ_DK)
                .jumpUrls(list)
                .build();
    }

    @Override
    public String getContext(List<ConsecutiveAbsenceModel> dataList) {

        if (null == dataList || dataList.isEmpty()) {
            return "";
        }
        ConsecutiveAbsenceModel model = dataList.get(0);
        return "考勤组：" + model.getGroupName() + "</br>" +
                "成员：" + model.getUserName() + "</br>" +
                "考勤时间：" + model.getAbsenceDate();
    }
}
