package cn.estsh.i3plus.pojo.platform.bean;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description :
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2020-09-13 17:35
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name="SYS_SOFT_UPDATE_RECORD")
@ApiModel(value="软件更新记录",description = "软件更新记录")
public class SysSoftUpdateRecord extends BaseBean {

    @Column(name="SYSTEM_SOFT_TYPE")
    @ApiParam(value ="系统软件类型")
    private Integer systemSoftType;

    public String getSystemSoftTypeTxt(){
        return systemSoftType == null ? "无" : CommonEnumUtil.SOFT_TYPE.valueOfDescription(systemSoftType);
    }

    @Column(name="SYSTEM_VERSION")
    @ApiParam(value ="系统版本")
    private String systemVersion;

    @Lob
    @Column(name="UPDATE_CONTENT")
    @ApiParam(value ="更新内容")
    private String updateContent;

    @Column(name="FIRST_DEPLOYMENT_TIME")
    @ApiParam(value ="首次部署时间")
    private String firstDeploymentTime;

    @Transient
    private Map<String, List<String>> updateDetailMap;

    public void putUpdateDetail(String detailType, String detail) {
        if(updateDetailMap == null){
            updateDetailMap = new HashMap<>();
        }

        List<String> detailList;
        if (updateDetailMap.containsKey(detailType)) {
            detailList = updateDetailMap.get(detailType);
        } else {
            detailList = new ArrayList<>();
            updateDetailMap.put(detailType, detailList);
        }

        detailList.add(detail);
    }

    public void transformUpdateDetail() {
        this.updateContent = JSON.toJSONString(updateDetailMap);
    }
}
