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 javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "modev")
@ApiModel("监测装置表")
public class Modev {

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

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

    @NotNull(message = "监测设备类型不能缺少")
    @Column(name = "modevtid")
    @ApiModelProperty("监测设备类型编号")
    private Integer modevtid;

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

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

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

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

    @Column(name = "zsbid")
    @NotNull(message = "主设备编号不能缺少")
    @ApiModelProperty("主设备编号")
    private Integer zsbid;

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

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

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

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

    @Column(name = "manufacturedate")
    private Date manufacturedate;

    @Column(name = "rundate")
    private Date rundate;

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

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

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

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

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

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

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

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

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

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

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

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

    @ApiModelProperty("主设备名称")
    @Transient
    private String zsbname;

    @ApiModelProperty("监测设备类型名称")
    @Transient
    private String modevtname;

    public NSensor transform(){
        NSensor sensor = NSensor.builder()
                .name(name)
                .typeId(modevtid)
                .devId(id)
                .zsbId(zsbid)
                .build();
        return sensor;
    }
}