package com.kamco.cd.kamcoback.label.dto;

import com.kamco.cd.kamcoback.common.utils.enums.CodeExpose;
import com.kamco.cd.kamcoback.common.utils.enums.EnumType;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

public class LabelAllocateDto {

  @CodeExpose
  @Getter
  @AllArgsConstructor
  public enum LabelMngState implements EnumType {
    PENDING("작업대기"),
    ASSIGNED("작업할당"),
    STOP("중단"),
    LABEL_ING("라벨진행중"),
    LABEL_COMPLETE("라벨완료"),
    INSPECT_REQ("검수요청"),
    INSPECT_ING("검수진행중"),
    INSPECT_COMPLETE("검수완료");

    private String desc;

    @Override
    public String getId() {
      return name();
    }

    @Override
    public String getText() {
      return desc;
    }
  }

  @CodeExpose
  @Getter
  @AllArgsConstructor
  public enum LabelState implements EnumType {
    WAIT("대기"),
    ASSIGNED("배정"),
    SKIP("스킵"),
    DONE("완료"),
    COMPLETE("완료");

    private String desc;

    @Override
    public String getId() {
      return name();
    }

    @Override
    public String getText() {
      return desc;
    }
  }

  @CodeExpose
  @Getter
  @AllArgsConstructor
  public enum InspectState implements EnumType {
    UNCONFIRM("미확인"),
    EXCEPT("제외"),
    COMPLETE("완료");

    private String desc;

    @Override
    public String getId() {
      return name();
    }

    @Override
    public String getText() {
      return desc;
    }
  }

  @Getter
  @Setter
  @AllArgsConstructor
  public static class AllocateDto {

    //    @Schema(description = "분석 ID", example = "3")
    //    private Long analUid;

    @Schema(description = "비교년도", example = "2022", required = true)
    private Integer compareYyyy;

    @Schema(description = "기준년도", example = "2024", required = true)
    private Integer targetYyyy;

    @Schema(description = "라벨러 자동/수동여부(AUTO/MANUAL)", example = "AUTO")
    private String labelerAutoType;

    @Schema(description = "검수자 자동/수동여부(AUTO/MANUAL)", example = "AUTO")
    private String inspectorAutoType;

    @Schema(description = "회차", example = "4")
    private Integer stage;

    @Schema(
        description = "라벨러 할당 목록",
        example =
            """
          [
             {
               "userId": "123456",
               "demand": 1000
             },
             {
               "userId": "010222297501",
               "demand": 400
             },
             {
               "userId": "01022223333",
               "demand": 440
             }
          ]
          """)
    private List<TargetUser> labelers;

    @Schema(
        description = "검수자 할당 목록",
        example =
            """
          [
             {
               "inspectorUid": "K20251216001",
               "userCount": 1000
             },
             {
                   "inspectorUid": "01022225555",
                   "userCount": 340
                 },
             {
               "inspectorUid": "K20251212001",
               "userCount": 500
             }
          ]
          """)
    private List<TargetInspector> inspectors;
  }

  @Getter
  public static class TargetUser {

    @Schema(description = "라벨러 사번", example = "labeler44")
    private final String userId;

    @Schema(description = "할당 건수", example = "200")
    private final int demand;

    public TargetUser(String userId, int demand) {
      this.userId = userId;
      this.demand = demand;
    }
  }

  @Getter
  @AllArgsConstructor
  public static class TargetInspector {

    @Schema(description = "검수자 사번", example = "K20251212001")
    private final String inspectorUid;

    @Schema(description = "할당 명수", example = "3")
    private int userCount;
  }

  @Getter
  @Setter
  @AllArgsConstructor
  public static class Basic {

    private UUID assignmentUid;
    private Long inferenceGeomUid;
    private String workerUid;
    private String inspectorUid;
    private String workState;
    private Character stagnationYn;
    private String assignGroupId;
    private Long learnGeomUid;
    private Long analUid;
    private ZonedDateTime createdDttm;
    private ZonedDateTime updatedDttm;
  }

  @Getter
  @Setter
  @AllArgsConstructor
  public static class UserList {

    private String userRole;
    private String employeeNo;
    private String name;
  }

  @Getter
  @Setter
  @AllArgsConstructor
  public static class InferenceDetail {

    private String analTitle;
    private Integer stage;
    private ZonedDateTime gukyuinDttm;
    private Long count;
    private Long labelCnt;
    private Long inspectorCnt;
  }

  @Getter
  @Setter
  @AllArgsConstructor
  public static class LabelerDetail {

    private String roleType;
    private String name;
    private String userId; // 사번
    private Long count;
    private Long completeCnt;
    private Long skipCnt;
    private Double percent;
    private Integer ranking;
    private ZonedDateTime createdDttm;
    private String inspectorName;
  }

  @Getter
  @Setter
  @AllArgsConstructor
  public static class AllocateMoveDto {

    @Schema(description = "자동/수동여부(AUTO/MANUAL)", example = "AUTO")
    private String autoType;

    @Schema(description = "회차", example = "4")
    private Integer stage;

    @Schema(
        description = "라벨러 할당 목록",
        example =
            """
          [
             {
               "userId": "123456",
               "demand": 10
             },
             {
               "userId": "010222297501",
               "demand": 5
             }
          ]
          """)
    private List<TargetUser> labelers;

    @Schema(description = "비교년도", example = "2022")
    private Integer compareYyyy;

    @Schema(description = "기준년도", example = "2024")
    private Integer targetYyyy;
  }

  @Getter
  @Setter
  @AllArgsConstructor
  public static class AllocateInfoDto {

    private Long geoUid;
    private String mapSheetNum;
  }
}
