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

import com.its.api.its.model.dto.vms.TbVmsUsagTypeDto;
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;

/**
 * VMS 용도 유형 Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("VMS 용도 유형")
@Entity
@Table(name = "TB_VMS_USAG_TYPE")
public class TbVmsUsagType implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("VMS 용도 유형 코드")  // N VARCHAR(5)
    @Id
    @Column(name = "VMS_USAG_TYPE_CD", nullable = false, length = 5)
    private String vmsUsagTypeCd;

    @ApiModelProperty("VMS 용도 유형 명")  // Y VARCHAR(40)
    @Column(name = "VMS_USAG_TYPE_NM", length = 40)
    private String vmsUsagTypeNm;

    @ApiModelProperty("VMS 용도 유형 영문 명")  // Y VARCHAR(40)
    @Column(name = "VMS_USAG_TYPE_ENGL_NM", length = 40)
    private String vmsUsagTypeEnglNm;

    @ApiModelProperty("사용 여부")  // Y CHAR(1)
    @Column(name = "USE_YN", columnDefinition = "CHAR", length = 1)
    private String useYn;

    public TbVmsUsagTypeDto toDto() {
        TbVmsUsagTypeDto dto = TbVmsUsagTypeDto.builder()
                .vmsUsagTypeCd(this.vmsUsagTypeCd)
                .vmsUsagTypeNm(this.vmsUsagTypeNm)
                .vmsUsagTypeEnglNm(this.vmsUsagTypeEnglNm)
                .useYn(this.useYn)
                .build();

        dto.setVmsUsagTypeDesc("[" + dto.getVmsUsagTypeCd() + "] " + dto.getVmsUsagTypeNm());

        return dto;
    }

    public TbVmsUsagType(String vmsUsagTypeCd) {
        this.vmsUsagTypeCd = vmsUsagTypeCd;
    }

    public void updateInfo(TbVmsUsagTypeDto.TbVmsUsagTypeUpdReq req) {
        this.vmsUsagTypeNm = req.getVmsUsagTypeNm();
        this.vmsUsagTypeEnglNm = req.getVmsUsagTypeEnglNm();
        this.useYn = req.getUseYn();
    }

}
