package com.inspect.calender.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.inspect.calender.enums.TaskStateEnum;
import lombok.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class DailyTaskStatsDTO {
    @JsonIgnore
    private Integer taskState;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime startTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime endTime;

    private String id;
    private String name;
    private String status;
    private String start;
    private String end;

    public void formatTimeAndStatus() {
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        this.status = TaskStateEnum.getByCode(this.taskState);

        // 开始时间拆分
        if (startTime != null) {
            this.start = startTime.format(dateFormatter);
        }

        // 结束时间拆分
        if (endTime != null) {
            this.end = endTime.format(dateFormatter);
        }
    }
}
