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

import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
import io.swagger.v3.oas.annotations.media.Schema;
import java.math.BigDecimal;
import java.time.ZonedDateTime;
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 ModelMgmtDto {

  @Schema(name = "ModelMgmtDto Basic", description = "모델관리 엔티티 기본 정보")
  @Getter
  @NoArgsConstructor
  public static class Basic {

    private String modelVer;
    private String hyperVer;
    private String epochVer;
    private String dockerFileNm;

    @JsonFormatDttm private ZonedDateTime createCompleteDttm;
    @JsonFormatDttm private ZonedDateTime recentUseDttm;
    private Boolean deleted;
    @JsonFormatDttm private ZonedDateTime createdDttm;
    private Long createdUid;

    @JsonFormatDttm private ZonedDateTime updatedDttm;
    private Long updatedUid;

    public Basic(
        String modelVer,
        String hyperVer,
        String epochVer,
        String dockerFileNm,
        ZonedDateTime createCompleteDttm,
        ZonedDateTime recentUseDttm,
        Boolean deleted,
        ZonedDateTime createdDttm,
        Long createdUid,
        ZonedDateTime updatedDttm,
        Long updatedUid) {
      this.modelVer = modelVer;
      this.hyperVer = hyperVer;
      this.epochVer = epochVer;
      this.dockerFileNm = dockerFileNm;
      this.createCompleteDttm = createCompleteDttm;
      this.recentUseDttm = recentUseDttm;
      this.deleted = deleted;
      this.createdDttm = createdDttm;
      this.createdUid = createdUid;
      this.updatedDttm = updatedDttm;
      this.updatedUid = updatedUid;
    }
  }

  @Schema(name = "ModelList", description = "모델관리 목록")
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class ModelList {
    private Integer rowNum;
    private String modelVer;
    private String dockerFileNm;
    private String modelType;
    private String createCompleteDttm;
    private String recentUseDttm; // TODO: 추론관리 테이블 나오면 분석진행중일 때 사용중으로 리턴하기
    private BigDecimal f1Score;
    private BigDecimal precision;
    private BigDecimal recall;
    private BigDecimal accuracy;
    private BigDecimal iou;
    private Boolean deleted;
  }

  @Schema(name = "ModelAddReq", description = "모델 등록 req")
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class AddReq {

    private String modelType;
    private String dockerFileNm;
    private String modelVer;
    private String hyperVer;
    private String epochVer;
  }

  @Schema(name = "searchReq", description = "검색 요청")
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class searchReq {

    // 페이징 파라미터
    private int page = 0;
    private int size = 20;
    private String sort;

    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);
    }
  }
}
