package com.kamco.cd.training.hyperparam.dto;

import com.kamco.cd.training.common.enums.ModelType;
import com.kamco.cd.training.common.utils.enums.CodeExpose;
import com.kamco.cd.training.common.utils.enums.EnumType;
import com.kamco.cd.training.common.utils.interfaces.JsonFormatDttm;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.UUID;
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 HyperClsParamDto {

  @Schema(name = "Basic", description = "하이퍼파라미터 조회")
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class Basic {

    private ModelType model; // 20250212 modeltype추가
    private UUID uuid;
    private String hyperVer;
    @JsonFormatDttm private ZonedDateTime createdDttm;
    @JsonFormatDttm private ZonedDateTime lastUsedDttm;
    private Integer totalUseCnt;

    // -------------------------
    // Model
    // -------------------------
    private String inputSize;
    private Integer batchSize;
    private Integer workers;

    // -------------------------
    // Augmentation
    // -------------------------
    private Double scale;
    private Double translate;
    private Double fliplr;
    private Double flipud;
    private Double erasing;
    private Double mixup;
    private Double hsvH;
    private Double hsvS;
    private Double hsvV;
    private Double dropout;
    private Double labelSmoothing;

    // -------------------------
    // Memo
    // -------------------------
    private String memo;

    // -------------------------
    // Hardware
    // -------------------------
    private Boolean isDefault;
  }

  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class List {
    private UUID uuid;
    private ModelType model;
    private String hyperVer;
    @JsonFormatDttm private ZonedDateTime createDttm;
    @JsonFormatDttm private ZonedDateTime lastUsedDttm;
    private String memo;
    private Integer totalUseCnt;
  }

  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class SearchReq {
    private String type;
    private LocalDate startDate;
    private LocalDate endDate;
    private String hyperVer;

    // 페이징 파라미터
    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);
    }
  }

  @CodeExpose
  @Getter
  @AllArgsConstructor
  public enum HyperType implements EnumType {
    CREATE_DATE("생성일"),
    LAST_USED_DATE("최근 사용일");

    private final String desc;

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

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