package com.its.vms.dto;

import com.its.vms.entity.TbVmsSymbLib;
import com.its.vms.entity.eVmsImageType;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *  DTO Class
 */
@Data
@Builder
public class TbVmsSymbLibDto implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer symbLibNmbr;
    private String rgstDt;
    private byte[] redData;
    private byte[] greenData;
    private String symbExpl;
    private byte[] imagData;
    private String vmsTypeCd;
    private String symbImagType;
    private String symbFileNm;
    private String symbType;
    private byte[] aviData;
    private Long imagSize;
    private Long playTm;
    private String delYn;
    private String updtDt;
    private Integer posX;
    private Integer posY;

    public TbVmsSymbLib toEntity() {
        // 소통정보이미지 때문에 이미지번호에 "0" 을 추가하여 이미지번호로 사용함

        TbVmsSymbLib obj = TbVmsSymbLib.builder()
                .symbLibNmbr(this.symbLibNmbr+"0")
                .orgSymbLibNmbr(this.symbLibNmbr)
                .rgstDt(this.rgstDt)
                .redData(this.redData)
                .greenData(this.greenData)
                .symbExpl(this.symbExpl)
                .imagData(this.imagData)
                .vmsTypeCd(this.vmsTypeCd)
                .symbImagType(this.symbImagType)
                .symbFileNm(this.symbFileNm)
                .symbType(this.symbType)
                .aviData(this.aviData)
                .imagSize(this.imagSize)
                .playTm(this.playTm)
                .delYn(this.delYn)
                .updtDt(this.updtDt)
                .posX(this.posX)
                .posY(this.posY)
                .gradSymbLibNmbrList(new ArrayList<>())
                .cellMap(new HashMap<>())
                .build();

        TbVmsSymbLibDto.setSymbInfo(obj);

        return obj;
    }

    public static void setSymbInfo(TbVmsSymbLib obj) {
        obj.setImagType(eVmsImageType.vms_image_type_bmp);

        String symbFileName = "";
        if ("SBT3".equals(obj.getSymbType())) {
            symbFileName = obj.getSymbFileNm();
            obj.setImagType(eVmsImageType.vms_image_type_video);
        }
        else {
            switch(obj.getImagType()) {
                case vms_image_type_bmp: symbFileName = obj.getSymbLibNmbr()+".bmp"; break;
                case vms_image_type_gif: symbFileName = obj.getSymbLibNmbr()+".gif"; break;
                case vms_image_type_jpg: symbFileName = obj.getSymbLibNmbr()+".jpg"; break;
                case vms_image_type_png: symbFileName = obj.getSymbLibNmbr()+".png"; break;
                default:
                    if (obj.getSymbFileNm() == null || obj.getSymbFileNm().trim().length() == 0) {
                        symbFileName = obj.getSymbLibNmbr()+".avi";
                    }
                    else {
                        symbFileName = obj.getSymbFileNm().trim();
                    }
                    break;
            }
        }
        obj.setSymbFileNm(symbFileName);
        obj.setLocalFileName(symbFileName);
    }
}
