package com.zioinfo.esn.uiws.worklog.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.zioinfo.esn.uiws.worklog.model.UiwsWorklogDtl;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

import java.util.List;

/**
 * 업무일지(모듈 06) DTO. 원본 com.urp.uiws.worklog.dto.* 이식(shape 동일, _state 보존).
 */
public final class WorklogDtos {

    private WorklogDtos() {
    }

    public record WorklogListDto(
            Long worklogId,
            String title,
            String writerNm,
            String workDate,
            String progressCd,
            long commentCount
    ) {
    }

    public record WorklogCalendarDto(
            String workDate,
            Long worklogId,
            String workStatusNm,
            boolean isHoliday,
            String holidayNm
    ) {
    }

    public record WorklogDetailDto(
            Long worklogId,
            String title,
            String writerId,
            String writerNm,
            String workDate,
            String workStatusCd,
            String progressCd,
            String repeatYn,
            String repeatStartDate,
            String repeatEndDate,
            List<WorklogDtlDto> details,
            List<WorklogCommentDto> comments
    ) {
    }

    public record WorklogDtlDto(
            Long dtlId,
            Integer startHour,
            Integer endHour,
            String workTypeCd,
            String companyId,
            String workContent,
            String issueContent,
            Integer sortOrd,
            String createdAt,
            String updatedAt,
            @JsonProperty("_state") String state
    ) {
        public static WorklogDtlDto from(UiwsWorklogDtl d) {
            return new WorklogDtlDto(
                    d.getDtlId(), d.getStartHour(), d.getEndHour(), d.getWorkTypeCd(), d.getCompanyId(),
                    d.getWorkContent(), d.getIssueContent(), d.getSortOrd(),
                    d.getCreatedAt() != null ? d.getCreatedAt().toString() : null,
                    d.getUpdatedAt() != null ? d.getUpdatedAt().toString() : null,
                    null);
        }
    }

    public record WorklogSaveDto(
            @NotBlank String title,
            @NotBlank String writerId,
            @NotNull String workDate,
            @NotBlank String workStatusCd,
            String progressCd,
            String repeatYn,
            String repeatStartDate,
            String repeatEndDate,
            @Valid List<WorklogDtlDto> details
    ) {
    }

    public record WorklogCommentDto(
            Long cmtId,
            String cmtContent,
            String writerNm,
            String createdAt,
            String kakaoSentYn,
            String confirmYn
    ) {
    }

    public record CommentRequest(@NotBlank String cmtContent) {
    }

    public record ProgressSummaryDto(String progressCd, String progressNm, long count) {
    }

    public record UnconfirmedCommentDto(
            Long cmtId,
            Long worklogId,
            String worklogTitle,
            String writerNm,
            String cmtContent,
            String createdAt
    ) {
    }

    public record WorklogPage(List<WorklogListDto> content, long totalElements, int page, int size, int totalPages) {
    }
}
