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

import com.kamco.cd.kamcoback.common.enums.RoleType;
import com.kamco.cd.kamcoback.common.utils.interfaces.EnumValid;
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
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;

public class MembersDto {

  @Getter
  @Setter
  public static class Basic {

    private Long id;
    private UUID uuid;
    private String employeeNo;
    private String name;
    private String email;
    private String status;
    private String roleName;
    @JsonFormatDttm private ZonedDateTime createdDttm;
    @JsonFormatDttm private ZonedDateTime updatedDttm;

    public Basic(
        Long id,
        UUID uuid,
        String employeeNo,
        String name,
        String email,
        String status,
        String roleName,
        ZonedDateTime createdDttm,
        ZonedDateTime updatedDttm) {
      this.id = id;
      this.uuid = uuid;
      this.employeeNo = employeeNo;
      this.name = name;
      this.email = email;
      this.status = status;
      this.roleName = roleName;
      this.createdDttm = createdDttm;
      this.updatedDttm = updatedDttm;
    }
  }

  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class SearchReq {

    @Schema(description = "이름(name), 이메일(email), 사번(employeeNo)", example = "name")
    private String field;

    @Schema(description = "키워드", example = "홍길동")
    private String keyword;

    @Schema(description = "라벨러 포함 여부", example = "true")
    private boolean labeler = true;

    @Schema(description = "검수자 포함 여부", example = "true")
    private boolean reviewer = true;

    @Schema(description = "운영자 포함 여부", example = "true")
    private boolean admin = true;

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

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

    public Pageable toPageable() {
      return PageRequest.of(page, size);
    }
  }

  @Getter
  @Setter
  public static class AddReq {

    @Schema(description = "사번", example = "11111")
    @NotBlank
    @Size(max = 50)
    private String employeeNo;

    @Schema(description = "이름", example = "홍길동")
    @NotBlank
    @Size(min = 2, max = 100)
    private String name;

    @Schema(hidden = true)
    private String password;

    @Schema(description = "이메일", example = "gildong@daum.net")
    @Size(max = 100)
    private String email;

    public AddReq(String employeeNo, String name, String password, String email) {
      this.employeeNo = employeeNo;
      this.name = name;
      this.password = password;
      this.email = email;
    }
  }

  @Getter
  @Setter
  public static class UpdateReq {

    @Schema(description = "사번, 패스워드 변경시 필수 값", example = "11111")
    @Size(max = 50)
    private String employeeNo;

    @Schema(description = "이름", example = "홍길동")
    @Size(min = 2, max = 100)
    private String name;

    @Schema(description = "패스워드", example = "")
    @Size(max = 255)
    private String password;

    @Schema(description = "이메일", example = "gildong@daum.net")
    @Size(max = 100)
    private String email;

    public UpdateReq(String employeeNo, String name, String password, String email) {
      this.employeeNo = employeeNo;
      this.name = name;
      this.password = password;
      this.email = email;
    }
  }

  @Getter
  @Setter
  public static class RolesDto {

    @Schema(description = "UUID", example = "4e89e487-c828-4a34-a7fc-0d5b0e3b53b5")
    private UUID uuid;

    @Schema(description = "역할 ROLE_ADMIN, ROLE_LABELER, ROLE_REVIEWER", example = "ROLE_ADMIN")
    @EnumValid(enumClass = RoleType.class)
    private String roleName;

    public RolesDto(UUID uuid, String roleName) {
      this.uuid = uuid;
      this.roleName = roleName;
    }
  }

  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  public static class StatusDto {

    @Schema(description = "UUID", example = "4e89e487-c828-4a34-a7fc-0d5b0e3b53b5")
    @NotBlank
    private UUID uuid;

    @Schema(description = "변경할 상태값 ACTIVE, INACTIVE, ARCHIVED", example = "ACTIVE")
    @NotBlank
    private String status;
  }
}
