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

import com.gyee.wisdom.common.data.ToData;
import com.gyee.wisdom.common.data.control.ControlLog;
import com.gyee.wisdom.common.data.control.GycpCmdInfo;
import com.gyee.wisdom.dao.sql.ModelConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

/**
 * @descrition:
 * @author:Wanghs
 * @date:2019-09-03
 */
@Data
@NoArgsConstructor
@ToString
@EqualsAndHashCode()
@Entity
@Table(name = ModelConstants.CONTROL_INFO)
public class ControlLogEntity implements ToData<ControlLog> {

    @Id
    @Column(name = ModelConstants.ID_)
    private int id;

    @Column(name = ModelConstants.TYPE_)
    private int type;

    @Column(name = ModelConstants.Time)
    private Date time;

    @Column(name = ModelConstants.USER_ID)
    private int userId;

    @Column(name = ModelConstants.WINDTURBINE_ID)
    private String windturbineId;

    @Column(name = ModelConstants.WINPOWERSATIONID_)
    private String stationId;

    @Column(name = ModelConstants.CMD_ID)
    private int cmdId;

    @Column(name = ModelConstants.ISSUCCESS)
    private boolean success;

    @Column(name = ModelConstants.CONTROL_ERRORS_CODE)
    private String controlErrorsCode;

    public ControlLogEntity(ControlLog data) {
        this.type = data.getType();
        this.time = data.getTime();
        this.userId = data.getUserId();
        this.windturbineId = data.getWindturbineId();
        this.stationId = data.getStationId();
        this.cmdId = data.getCmdId();
        this.success = data.isSuccess();
        this.controlErrorsCode = data.getControlErrorsCode();
    }

    @Override
    public ControlLog toData() {

        ControlLog data = new ControlLog();
        data.setId(this.getId());
        data.setType(this.getType());
        data.setTime(this.getTime());
        data.setUserId(this.getUserId());
        data.setWindturbineId(this.getWindturbineId());
        data.setStationId(this.getStationId());
        data.setCmdId(this.getCmdId());
        data.setSuccess(this.isSuccess());
        data.setControlErrorsCode(this.getControlErrorsCode());
        return data;
    }
}
