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

import incheon.ags.ias.user.vo.UserVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.sql.Timestamp;

@Getter
@Setter
public class UserRequestDTO {
    @Schema(description = "사용자 고유 ID", example = "USR001", required = true)
    private String userUnqId;

    @Schema(description = "사용자 ID", example = "admin", required = true)
    @NotBlank(message = "사용자 ID는 필수 항목입니다.")
    @Size(min = 3, max = 20, message = "사용자 ID는 3-20자 사이여야 합니다.")
    @Pattern(regexp = "^[a-zA-Z0-9_]+$", message = "사용자 ID는 영문, 숫자, 언더스코어만 사용 가능합니다.")
    private String userId;

    @Schema(description = "사용자 상태 코드", example = "ACTIVE")
    private String userStcd;

    @Schema(description = "사용자명", example = "홍길동")
    @NotBlank(message = "사용자명은 필수 항목입니다.")
    @Size(max = 100, message = "사용자명은 100자를 초과할 수 없습니다.")
    private String userNm;

    @Schema(description = "부서 코드", example = "DEPT001")
    private String deptCd;

    @Schema(description = "부서명", example = "정보화담당관")
    private String deptNm;

    @Schema(description = "직급 코드", example = "POS001")
    private String jbgdCd;

    @Schema(description = "직급명", example = "사원")
    private String jbgdNm;

    @Schema(description = "직책 코드", example = "JOB001")
    private String jbpsCd;

    @Schema(description = "직책명", example = "팀장")
    private String jbpsNm;

    @Schema(description = "사무실 전화번호", example = "0324567890")
    private String ofcTelno;

    @Schema(description = "이메일 주소", example = "admin@incheon.go.kr")
    @Email(message = "올바른 이메일 형식이 아닙니다.")
    @Size(max = 320, message = "이메일 주소는 320자를 초과할 수 없습니다.")
    private String emlAddr;

    @Schema(description = "휴대전화번호", example = "01012345678")
    private String mblTelno;

    @Schema(description = "대표기관코드", example = "6280000")
    private String rprsInstCd;

    @Schema(description = "대표기관명", example = "인천광역시")
    private String rprsInstNm;

    @Schema(description = "변경할 사용자 ID", example = "admin12")
    private String updtUserId;

    @Schema(description = "최초 등록자 ID", example = "system")
    private String frstRegId;

    @Schema(description = "최초 등록일시", example = "2025-01-20 10:30:00")
    private Timestamp frstRegDt;

    @Schema(description = "최종 수정자 ID", example = "admin")
    private String lastMdfcnId;

    @Schema(description = "최종 수정일시", example = "2025-01-20 10:30:00")
    private Timestamp lastMdfcnDt;

    public UserVO toEntity() {
        UserVO vo = new UserVO();
        vo.setUserUnqId(this.userUnqId);
        vo.setUserId(this.userId);
        vo.setUserStcd(this.userStcd);
        vo.setUserNm(this.userNm);
        vo.setDeptCd(this.deptCd);
        vo.setDeptNm(this.deptNm);
        vo.setJbgdCd(this.jbgdCd);
        vo.setJbgdNm(this.jbgdNm);
        vo.setJbpsCd(this.jbpsCd);
        vo.setJbpsNm(this.jbpsNm);
        vo.setOfcTelno(this.ofcTelno);
        vo.setEmlAddr(this.emlAddr);
        vo.setMblTelno(this.mblTelno);
        vo.setRprsInstCd(this.rprsInstCd);
        vo.setRprsInstNm(this.rprsInstNm);
        vo.setUpdtUserId(this.updtUserId);
        vo.setFrstRegId(this.frstRegId);
        vo.setFrstRegDt(this.frstRegDt);
        vo.setLastMdfcnId(this.lastMdfcnId);
        vo.setLastMdfcnDt(this.lastMdfcnDt);
        return vo;
    }
}