package org.nl.acs.device_driver.tianneng.tubanxian;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Data
public class ItemProtocol {

    public static String item_heartbeat = "heartbeat";
    public static String item_mode = "mode";
    public static String item_status = "status";
    public static String item_error = "error";
    public static String item_open_time = "open_time";
    public static String item_standby_time = "standby_time";
    public static String item_production_time = "production_time";
    public static String item_error_time = "error_time";
    public static String item_end_time = "end_time";
    public static String item_weight = "weight";
    public static String item_order_No = "order_No";
    public static String item_material = "material";
    public static String item_number = "number";
    public static String item_to_command = "to_command";
    public static String item_to_order_No = "to_order_No";
    public static String item_to_material_code = "to_material_code";
    public static String item_to_number = "to_number";

    private TubanxianSiteDeviceDriver driver;

    public ItemProtocol(TubanxianSiteDeviceDriver driver) {
        this.driver = driver;
    }

    public int getHeartbeat() {
        return this.getOpcIntegerValue(item_heartbeat);
    }

    public int getMode() {
        return this.getOpcIntegerValue(item_mode);
    }

    public int getItem_status() {
        return this.getOpcIntegerValue(item_status);
    }

    public int getItem_error() {
        return this.getOpcIntegerValue(item_error);
    }

    public int getItem_open_time() {
        return this.getOpcIntegerValue(item_open_time);
    }

    public int getItem_standby_time() {
        return this.getOpcIntegerValue(item_standby_time);
    }

    public int getItem_production_time() {
        return this.getOpcIntegerValue(item_production_time);
    }

    public int getItem_error_time() {
        return this.getOpcIntegerValue(item_error_time);
    }

    public int getItem_end_time() {
        return this.getOpcIntegerValue(item_end_time);
    }

    public int getItem_weight() {
        return this.getOpcIntegerValue(item_weight);
    }

    public int getItem_order_No() {
        return this.getOpcIntegerValue(item_order_No);
    }

    public int getItem_material() {
        return this.getOpcIntegerValue(item_material);
    }

    public int getItem_number() {
        return this.getOpcIntegerValue(item_number);
    }

    public int getItem_to_command() {
        return this.getOpcIntegerValue(item_to_command);
    }

    public int getItem_to_order_No() {
        return this.getOpcIntegerValue(item_to_order_No);
    }

    public int getItem_to_material_code() {
        return this.getOpcIntegerValue(item_to_material_code);
    }

    public int getItem_to_number() {
        return this.getOpcIntegerValue(item_to_number);
    }

    Boolean isonline;

    public int getOpcIntegerValue(String protocol) {
        Integer value = this.driver.getIntegeregerValue(protocol);
        if (value == null) {
            // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
            setIsonline(false);
        } else {
            setIsonline(true);
            return value;
        }
        return 0;

    }

    public static List<ItemDto> getReadableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0"));
        list.add(new ItemDto(item_mode, "工作状态", "DB600.B2"));
        list.add(new ItemDto(item_status, "设备状态", "DB600.B3"));
        list.add(new ItemDto(item_error, "error", "DB600.B4"));
        list.add(new ItemDto(item_open_time, "当前开机时间", "DB600.D6"));
        list.add(new ItemDto(item_standby_time, "当前待机时间", "DB600.B7"));
        list.add(new ItemDto(item_production_time, "当前生产时间", "DB600.B3"));
        list.add(new ItemDto(item_error_time, "当前故障时间", "DB600.D8"));
        list.add(new ItemDto(item_end_time, "当前关机时间", "DB600.B3"));
        list.add(new ItemDto(item_weight, "本次称重重量", "DB600.B4"));
        list.add(new ItemDto(item_order_No, "工单号", "DB600.D6"));
        list.add(new ItemDto(item_error, "error", "DB600.B7"));
        list.add(new ItemDto(item_material, "当前生产物料", "DB600.D8"));
        list.add(new ItemDto(item_number, "当前生产数量", "DB600.D8"));
        return list;
    }

    public static List<ItemDto> getWriteableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "作业命令", "DB601.W2", Boolean.valueOf(true)));
        list.add(new ItemDto(item_to_order_No, "工单号", "DB601.W2"));
        list.add(new ItemDto(item_to_material_code, "下发物料编号", "DB601.W2"));
        list.add(new ItemDto(item_to_number, "下发生产数量", "DB601.W2"));
        return list;
    }

}

