package incheon.ags.ias.srvy.srvyRspdnt.web.dto;

import incheon.ags.ias.srvy.srvyRspdnt.vo.SrvyRspdntVO;
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.sql.Timestamp;
import java.time.LocalDateTime;

@Getter
@Setter
public class SrvyRspdntRequestDTO {

    @Schema(description = "설문조사 일련번호", example = "1", required = true)
    @NotNull(message = "설문조사 일련번호는 필수 항목입니다.")
    private Integer srvySn;

    @Schema(description = "설문응답자 일련번호", example = "1")
    private Integer srvyRspdntSn;

    @Schema(description = "응답자명", example = "홍길동", required = true)
    @NotBlank(message = "응답자명은 필수 항목입니다.")
    private String rspdntNm;

    @Schema(description = "응답자 아이디", example = "hong123", required = true)
    @NotBlank(message = "응답자 아이디는 필수 항목입니다.")
    private String rspdntId;

    @Schema(description = "성별 코드", example = "M")
    private String gndrCd;

    @Schema(description = "연령대 코드", example = "AGE_20")
    private String ageGrpCd;

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

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


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

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

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

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

    public SrvyRspdntVO toEntity() {
        SrvyRspdntVO vo = new SrvyRspdntVO();
        vo.setSrvySn(this.srvySn);
        vo.setSrvyRspdntSn(this.srvyRspdntSn);
        vo.setRspdntNm(this.rspdntNm);
        vo.setRspdntId(this.rspdntId);
        vo.setGndrCd(this.gndrCd);
        vo.setAgeGrpCd(this.ageGrpCd);
        vo.setDeptCd(this.deptCd);
        vo.setJbgdCd(this.jbgdCd);
        vo.setFrstRegId(this.frstRegId);
        vo.setFrstRegDt(this.frstRegDt != null ? Timestamp.valueOf(this.frstRegDt) : null);
        vo.setLastMdfcnId(this.lastMdfcnId);
        vo.setLastMdfcnDt(this.lastMdfcnDt != null ? Timestamp.valueOf(this.lastMdfcnDt) : null);
        return vo;
    }
}
