package com.its.api.its.model.entity.database;

import com.its.api.its.global.CodeManager;
import com.its.api.its.model.dto.database.TbLeglHldyInfrDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * 공휴일 정보 Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("공휴일 정보")
@Entity
@Table(name = "TB_LEGL_HLDY_INFR")
public class TbLeglHldyInfr implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("년월일")  // N VARCHAR(8)
    @Id
    @Column(name = "YMD", nullable = false, length = 8)
    private String ymd;

    @ApiModelProperty("요일 유형 코드")  // Y VARCHAR(7)
    @Column(name = "DAY_TYPE_CD", length = 7)
    private String dayTypeCd;

    @ApiModelProperty("공휴일 명")  // Y VARCHAR(30)
    @Column(name = "LEGL_HLDY_NM", length = 30)
    private String leglHldyNm;

    @ApiModelProperty("비고")  // Y VARCHAR(200)
    @Column(name = "RMRK", length = 200)
    private String rmrk;

    public TbLeglHldyInfrDto toDto() {
        TbLeglHldyInfrDto dto = TbLeglHldyInfrDto.builder()
                .ymd(this.ymd)
                .dayTypeCd(this.dayTypeCd)
                .leglHldyNm(this.leglHldyNm)
                .rmrk(this.rmrk)
                .build();

        dto.setDayTypeDesc(CodeManager.getCodeDesc(CodeManager.HLDY_DAY_CD, this.dayTypeCd));

        return dto;
    }

    public TbLeglHldyInfr(String ymd) {
        this.ymd = ymd;
    }

    public void updateInfo(TbLeglHldyInfrDto.TbLeglHldyInfrUpdReq req) {
        this.dayTypeCd = req.getDayTypeCd();
        this.leglHldyNm = req.getLeglHldyNm();
        this.rmrk = req.getRmrk();
    }

}
