package com.mortals.xhx.module.attendance.service.work;

import cn.hutool.core.date.DateUtil;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.common.code.*;
import com.mortals.xhx.module.attendance.model.*;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 工作排班抽象类
 *
 * @author:
 * @date: 2023/7/31 15:09
 */
public abstract class AttendanceWorkAbstract {

    private int type;

    abstract int getType();

    abstract void initData();

   public abstract void   doHandleWork(CommonData commonData);


    public static AttendanceWorkAbstract newType(int type) {
        if (type == TypeEnum.固定班制.getValue()) {
            //return new FixWorkAttendance(type);
            return new FixWorkOtherAttendance(type);
        } else if (type == TypeEnum.自由工时.getValue()) {
            return new FreedomWorkAttendance(type);
        }
        if (type == TypeEnum.排班制.getValue()) {
            return new ScheduleWorkAttendance(type);
        } else {
            throw new AppException(String.format("未知的类型码:%s", type));
        }

    }




    protected String getWeek(Date date) {
        // Get the day of the week (1 = Sunday, 2 = Monday, ..., 7 = Saturday)
        int dayOfWeek = DateUtil.dayOfWeek(date);
        // Map the numeric day of the week to its corresponding Chinese name
        String[] dayOfWeekNames = new String[]{
                "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"
        };
        // Get the Chinese name of the day of the week
        String dayOfWeekName = dayOfWeekNames[dayOfWeek - 1];
        return dayOfWeekName;
    }


    /**
     * 获取通过星期获取班次id  如果返参为-1 则不在考勤
     *
     * @return
     */
    protected Long getWeekClassId(AttendanceGroupFixedworkEntity attendanceGroupFixedworkEntity, String week) {
        Long weekClassId = 0L;
        switch (week) {
            case "星期一":
                if (attendanceGroupFixedworkEntity.getMonday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getMondayClassId();
                break;
            case "星期二":
                if (attendanceGroupFixedworkEntity.getTuesday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getTuesdayClassId();
                break;
            case "星期三":
                if (attendanceGroupFixedworkEntity.getWednesday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getWednesdayClassId();
                break;
            case "星期四":
                if (attendanceGroupFixedworkEntity.getThursday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getThursdayClassId();
                break;
            case "星期五":
                if (attendanceGroupFixedworkEntity.getFriday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getFridayClassId();
                break;
            case "星期六":
                if (attendanceGroupFixedworkEntity.getSaturday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getSaturdayClassId();
                break;
            case "星期日":
                if (attendanceGroupFixedworkEntity.getSunday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getSundayClassId();
                break;
        }
        return weekClassId;
    }



    public AttendanceWorkAbstract(int type) {
        this.type = type;
    }

}
