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

import com.kamco.cd.kamcoback.config.enums.EnumType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

public class MapSheetMngDto {

  @Schema(name = "searchReq", description = "영상관리 오류데이터 검색 요청")
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class searchReq {

    // 페이징 파라미터
    @Schema(description = "페이지 번호 (0부터 시작) ", example = "0")
    private int page = 0;

    @Schema(description = "페이지 크기", example = "20")
    private int size = 20;

    @Schema(description = "정렬", example = "id desc")
    private String sort;

    @Schema(description = "검색어", example = "부산3959")
    private String searchValue;

    @Schema(description = "년도", example = "2025")
    private Integer mngYyyy;

    public Pageable toPageable() {
      if (sort != null && !sort.isEmpty()) {
        String[] sortParams = sort.split(",");
        String property = sortParams[0];
        Sort.Direction direction =
            sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC;
        return PageRequest.of(page, size, Sort.by(direction, property));
      }
      return PageRequest.of(page, size);
    }
  }

  @Schema(name = "ErrorDataDto", description = "영상관리 오류데이터 검색 리턴")
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class ErrorDataDto {
    private Long hstUid;
    private Integer rowNum;
    private String map50kName;
    private String map5kName;
    private Integer mapCodeSrc;
    private String createdDttm;
    private DataState dataState;
  }

  @Schema(name = "MngDto", description = "영상관리 검색 리턴")
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class MngDto {
    private int rowNum;
    private int mngYyyy;
    private String mngState;
    private String syncState;
    private String mngStateDttm;
    private String syncStateDttm;
    // private int sheetCnt;
    // private int exceptCnt;
    private String mngPath;
    private String createdDttm;
    private Long createdUid;
    private String updatedDttm;
    private Long updatedUid;
  }

  @Schema(name = "DmlReturn", description = "영상관리 DML 수행 후 리턴")
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class DmlReturn {
    private String flag;
    private String message;
  }

  @Getter
  @AllArgsConstructor
  public enum MngState implements EnumType {
    COMPLETE("업로드 완료"),
    IN_PROGRESS("진행중"),
    FAILED("오류");

    private final String desc;

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

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

  @Getter
  @AllArgsConstructor
  public enum SyncState implements EnumType {
    COMPLETE("동기화 완료"),
    IN_PROGRESS("진행중"),
    FAIL("오류"),
    NONE("미진행");

    private final String desc;

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

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

  @Getter
  @AllArgsConstructor
  public enum DataState implements EnumType {
    SUCCESS("정상"),
    FAIL("데이터 없음");

    private final String desc;

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

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