package incheon.ags.ias.authrt.web.dto;

import incheon.ags.ias.authrt.vo.AuthrtVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

@Getter
@Setter
public class AuthrtRequestDTO {

    @Schema(description = "권한 코드", example = "PERM_MENU_ACCESS", required = true)
    @NotBlank(message = "권한 코드는 필수 항목입니다.")
    private String authrtCd;

    @Schema(description = "권한명", example = "메뉴접근권한", required = true)
    @NotBlank(message = "권한명은 필수 항목입니다.")
    private String authrtNm;

    @Schema(description = "권한 설명", example = "메뉴 접근 권한")
    private String authrtExpln;

    @Schema(description = "권한 유형 코드", example = "PERMTY002", required = true)
    @NotBlank(message = "권한 유형 코드는 필수 항목입니다.")
    private String authrtTypeCd;

    @Schema(description = "시스템 코드", example = "SYS001", required = true)
    @NotBlank(message = "시스템 코드는 필수 항목입니다.")
    private String sysCd;

    @Schema(description = "사용 여부", example = "Y", required = true)
    @NotBlank(message = "사용 여부는 필수 항목입니다.")
    private String useYn;

    @Schema(description = "최초 등록자 ID", example = "ADMIN", required = true)
    @NotBlank(message = "최초 등록자 ID는 필수 항목입니다.")
    private String frstRegId;

    @Schema(description = "최초 등록 일시", example = "2025-01-15T09:00:00")
    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
    private LocalDateTime frstRegDt;

    @Schema(description = "최종 수정자 ID", example = "ADMIN", required = true)
    @NotBlank(message = "최종 수정자 ID는 필수 항목입니다.")
    private String lastMdfcnId;

    @Schema(description = "최종 수정 일시", example = "2025-01-16T10:00:00")
    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
    private LocalDateTime lastMdfcnDt;

    public AuthrtVO toEntity() {
        AuthrtVO vo = new AuthrtVO();
        vo.setAuthrtCd(this.authrtCd);
        vo.setAuthrtNm(this.authrtNm);
        vo.setAuthrtExpln(this.authrtExpln);
        vo.setAuthrtTypeCd(this.authrtTypeCd);
        vo.setSysCd(this.sysCd);
        vo.setUseYn(this.useYn);
        vo.setFrstRegId(this.frstRegId);
        vo.setFrstRegDt(this.frstRegDt);
        vo.setLastMdfcnId(this.lastMdfcnId);
        vo.setLastMdfcnDt(this.lastMdfcnDt);
        return vo;
    }
}