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

import incheon.ags.ias.role.vo.RoleVO;
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 RoleRequestDTO {

    @Schema(description = "역할 코드", example = "ROLE_BIZ_ADMIN", required = true)
    @NotBlank(message = "역할 코드는 필수 항목입니다.")
    private String roleCd;

    @Schema(description = "역할명", example = "업무관리자", required = true)
    @NotBlank(message = "역할명은 필수 항목입니다.")
    private String roleNm;

    @Schema(description = "역할 설명", example = "업무 시스템 관리자")
    private String roleExpln;

    @Schema(description = "역할 유형 코드", example = "ROLTYP002", required = true)
    @NotBlank(message = "역할 유형 코드는 필수 항목입니다.")
    private String roleTypeCd;

    @Schema(description = "상위 역할 코드", example = "ROLE_INTG_ADMIN")
    private String upRoleCd;

    @Schema(description = "역할 정렬 순서", example = "1", required = true)
    @NotNull(message = "역할 정렬 순서는 필수 항목입니다.")
    private Integer roleSortSeq;

    @Schema(description = "시스템 코드", example = "SYS001")
    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 RoleVO toEntity() {
        RoleVO vo = new RoleVO();
        vo.setRoleCd(this.roleCd);
        vo.setRoleNm(this.roleNm);
        vo.setRoleExpln(this.roleExpln);
        vo.setRoleTypeCd(this.roleTypeCd);
        vo.setUpRoleCd(this.upRoleCd);
        vo.setRoleSortSeq(this.roleSortSeq);
        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;
    }
}