package com.xydl.cac.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "icd_config_type_att")
@ApiModel("ICD配置类型属性表")
public class IcdConfigTypeAtt {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    @ApiModelProperty(name = "配置类型表id")
    @Column(name = "icd_config_type_id")
    private Integer icdConfigTypeId;

    @ApiModelProperty(name = "属性")
    @Column(name = "do_name")
    private String doName;

    @ApiModelProperty(name = "fc")
    @Column(name = "fc")
    private String fc;

    @ApiModelProperty(name = "lastName")
    @Column(name = "last_name")
    private String lastName;

    @ApiModelProperty(name = "备注")
    @Column(name = "description")
    private String description;

    @ApiModelProperty(name = "字段名")
    @Column(name = "col_name")
    private String colName;

    @ApiModelProperty(name = "实例")
    @Column(name = "insts")
    private String insts;

    @Transient
    private List<String> instList;

    public void addInst(String inst) {
        if (instList == null) {
            instList = new ArrayList<>();
        }
        if (!instList.contains(inst)) {
            instList.add(inst);
        }
    }

    public void buildInsts() {
        insts = instList.stream().collect(Collectors.joining(","));
    }

    public boolean containInst(String inst) {
        if (instList == null) {
            instList = Arrays.asList(insts.split(","));
        }
        return instList.contains(inst);
    }

    public String getParam() {
        return fc + "$" + doName + "$" + lastName;
    }

}