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 org.springframework.util.CollectionUtils;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "bdz")
@ApiModel("变电站表")
public class Bdz {

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

    @NotBlank(message = "名称不能为空")
    @Size(max = 50, message = "名称长度不能超过50个字符")
    @ApiModelProperty("名称")
    @Column(name = "mc")
    private String mc;

    @Column(name = "lx")
    private String lx;

    @Column(name = "pid")
    private String pid;

    @Column(name = "gkjip")
    private String gkjip;

    @Column(name = "xfport")
    private Integer xfport;

    @Column(name = "znxj")
    private Short znxj;

    @Column(name = "ztjcid")
    private String ztjcid;

    @Column(name = "enable")
    private BigDecimal enable;

    @Column(name = "xh")
    private BigDecimal xh;

    @Column(name = "bz")
    private String bz;

    @Column(name = "hascac")
    private Boolean hascac;

    @ApiModelProperty("坐标")
    @Column(name = "coordinate")
    private String coordinate;

    @ApiModelProperty("电压等级,单位kV")
    @Column(name = "voltagegrade")
    private Integer voltagegrade;

    @ApiModelProperty("规模,单位MW")
    @Column(name = "scale")
    private Float scale;

    @ApiModelProperty("说明")
    @Column(name = "note")
    private String note;

    @Column(name = "icon1")
    private String icon1;

    @Column(name = "icon2")
    private String icon2;

    @Column(name = "icon3")
    private String icon3;

    @Column(name = "icon4")
    private String icon4;

    @Column(name = "svgurl")
    private String svgurl;

    @Transient
    private List<Jg> children;

    public void addChild(Jg child, boolean ignoreEmpty) {
        if (children == null) {
            children = new ArrayList<>();
        }
        if (ignoreEmpty && CollectionUtils.isEmpty(child.getChildren())) {
        } else {
            children.add(child);
        }
    }

}