package org.dromara.project.domain.vo.constructionuser;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dromara.project.domain.BusAttendance;
import org.dromara.project.domain.enums.BusAttendanceCommuterEnum;

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

/**
 * @author lcj
 * @date 2025/4/8 17:38
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BusConstructionUserAttendanceByDay {

    /**
     * 上班打卡时间
     */
    private Date upClockTime;

    /**
     * 上班打卡图片id
     */
    private Long upClockPicId;

    /**
     * 上班打卡图片
     */
    private String upClockPic;

    /**
     * 下班打卡图片id
     */
    private Long downClockPicId;
    /**
     * 下班打卡图片
     */
    private String downClockPic;

    /**
     * 下班打卡时间
     */
    private Date downClockTime;

    public static BusConstructionUserAttendanceByDay build(List<BusAttendance> attendanceList) {
        if (attendanceList == null) {
            return null;
        }
        BusConstructionUserAttendanceByDay constructionUserAttendanceByDay = new BusConstructionUserAttendanceByDay();
        for (BusAttendance attendance : attendanceList) {
            if (attendance.getCommuter().equals(BusAttendanceCommuterEnum.CLOCKIN.getValue())) {
                constructionUserAttendanceByDay.setUpClockTime(attendance.getClockTime());
                if (attendance.getFacePic() != null) {
                    constructionUserAttendanceByDay.setUpClockPicId(Long.valueOf(attendance.getFacePic()));
                }
            } else if (attendance.getCommuter().equals(BusAttendanceCommuterEnum.CLOCKOUT.getValue())) {
                constructionUserAttendanceByDay.setDownClockTime(attendance.getClockTime());
                if (attendance.getFacePic() != null) {
                    constructionUserAttendanceByDay.setDownClockPicId(Long.valueOf(attendance.getFacePic()));
                }
            }
        }
        return constructionUserAttendanceByDay;
    }

}
