package com.its.op.entity.its.vms;

import com.its.op.dto.its.vms.TbVmsFontColrDto;
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_FONT_COLR")
public class TbVmsFontColr implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("VMS 글꼴 색상 코드")  // N NUMBER(3)
    @Id
    @Column(name = "VMS_FONT_COLR_CD", nullable = false, columnDefinition = "NUMBER", length = 3)
    private Integer vmsFontColrCd;

    @ApiModelProperty("VMS 글꼴 색상 명칭")  // Y VARCHAR(60)
    @Column(name = "VMS_FONT_COLR_NM", length = 60)
    private String vmsFontColrNm;

    @ApiModelProperty("VMS 글꼴 색상 값")  // Y NUMBER(10)
    @Column(name = "VMS_FONT_COLR_VAL", columnDefinition = "NUMBER", length = 10)
    private Long vmsFontColrVal;

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

    public TbVmsFontColrDto toDto() {
        TbVmsFontColrDto dto = TbVmsFontColrDto.builder()
                .vmsFontColrCd(this.vmsFontColrCd)
                .vmsFontColrNm(this.vmsFontColrNm)
                .vmsFontColrVal(this.vmsFontColrVal)
                .useYn(this.useYn)
                .build();

        int color = Math.toIntExact(this.vmsFontColrVal);
        dto.setColorR((color & 0x000000FF));
        dto.setColorG((color & 0x0000FF00) >> 8);
        dto.setColorB((color & 0x00FF0000) >> 16);
        dto.setVmsFontColrDesc("[" + dto.getVmsFontColrCd() + "] " + dto.getVmsFontColrNm());
        return dto;
    }

}
