package com.gyee.wisdom.dao.sql.Windturbine.entity;

import com.gyee.wisdom.common.data.windturbine.EquipmentModel;
import com.gyee.wisdom.common.data.ToData;
import com.gyee.wisdom.dao.sql.ModelConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.*;
import java.math.BigDecimal;


@Data
@NoArgsConstructor
@ToString
@EqualsAndHashCode()
@Entity
@Table(name = ModelConstants.EQUIPMENT_MODEL)
public class ModelEntity implements ToData<EquipmentModel> {
    /** 主键ID */
    @Id
    /*@GeneratedValue(strategy = GenerationType.IDENTITY)*/
    @Column(name = ModelConstants.ID_)
    private String id;
    /** 编码 */
    @Column(name = ModelConstants.CODE_)
    private String code;
    /** 名称 */
    @Column(name = ModelConstants.NAME_)
    private String name;
    /** 地址*/
    @Column(name = ModelConstants.DESCRITION_)
    private String descrition;
    /** 项目id */
    @Column(name = ModelConstants.POWER_PRODUCTION)
    private Double powerProduction;
    /** 顺序 */
    @Column(name = ModelConstants.CUTIN_WIND_SPEED)
    private Double cutinWindSpeed;
    @Column(name = ModelConstants.RATED_WIND_SPEED)
    private Double ratedWindSpeed;
    @Column(name = ModelConstants.CUTOUT_WIND_SPEED)
    private Double cutoutWindSpeed;
    /** 装机容量*/
    @Column(name = ModelConstants.WINDTURBINE_MANUFACTURER_ID)
    private String windturbineManufacturerId;
    /*装机单位*/
    @Column(name = ModelConstants.UNIT_)
    private String unit;
    @Column(name = ModelConstants.PHOTO_)
    private String photo;
    /*装机数量*/
    @Column(name = ModelConstants.SWEPT_AREA)
    private Double sweptArea;
    /*风场编号*/
    @Column(name = ModelConstants.EQUIPMENT_CATEGORY)
    private Integer equipmentCategory;
/*
    @OneToMany(mappedBy=ModelConstants.ID_,cascade = {CascadeType.MERGE,CascadeType.REFRESH},fetch=FetchType.EAGER)
    private List<WindturbineEntity> listwindturbine;

*/

    public ModelEntity(EquipmentModel model) {
        this.id=model.getId();
        this.code=model.getCode();
        this.name=model.getName();
        this.descrition=model.getDescription();
        this.powerProduction=model.getPowerProduction();
        this.cutinWindSpeed=model.getCutinWindSpeed();
        this.ratedWindSpeed=model.getRatedWindSpeed();
        this.cutoutWindSpeed=model.getCutinWindSpeed();
        this.windturbineManufacturerId=model.getWindturbineManufacturerId();
        this.unit=model.getUnit();
        this.photo=model.getPhoto();
        this.sweptArea=model.getSweptArea();
        this.equipmentCategory=model.getEquipmentCategory();
/*        List<WindturbineEntity> windturbinelist=new ArrayList<WindturbineEntity>();
        for(Windturbine windturbine:model.getListwindturbine()){
            WindturbineEntity wind=  new WindturbineEntity(windturbine);
            windturbinelist.add(wind);
        }
        listwindturbine=windturbinelist;*/
    }


    @Override
    public EquipmentModel toData() {
        if(this!=null) {
            EquipmentModel equipmentModel = new EquipmentModel();
            equipmentModel.setId(this.id);
            equipmentModel.setCode(this.code);
            equipmentModel.setName(this.name);
            equipmentModel.setDescription(this.descrition);
            equipmentModel.setPowerProduction(this.powerProduction);
            equipmentModel.setCutinWindSpeed(this.cutinWindSpeed);
            equipmentModel.setWindturbineManufacturerId(this.windturbineManufacturerId);
            equipmentModel.setUnit(this.getUnit());
            equipmentModel.setSweptArea(this.getSweptArea());
            equipmentModel.setEquipmentCategory(this.getEquipmentCategory());
            equipmentModel.setPhoto(this.getPhoto());
            equipmentModel.setRatedWindSpeed(this.getRatedWindSpeed());
            equipmentModel.setCutoutWindSpeed(this.getCutoutWindSpeed());
            equipmentModel.setEquipmentCategory(this.getEquipmentCategory());
            /*equipmentModel.setListwindturbine(DataUtil.convertDataList(this.getListwindturbine()));*/
            return equipmentModel;
        }else{
            return null;
        }
    }


}
