package org.nl.acs.device_driver.basedriver.plug_pull_device_site;

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 {

    //1/0	手动/自动
    public static String item_mode = "mode";
    //0/1	半自动/全自动
    public static String item_action = "action";
    //0/1	远程/本地控制
    public static String item_control = "control";
    //2	运行中
    //1	急停/故障
    //0	待机中
    public static String item_status = "status";
    //1	机头上有轴
    public static String item_move = "move";
    //1/0	穿轴中/穿轴完成
    public static String item_plug_finish = "plug_finish";
    //1/0	把轴中/拔轴完成
    public static String item_pull_finish = "pull_finish";
    //3寸轴穿轴次数
    public static String item_3plug_times = "3plug_times";
    //6寸轴穿轴次数
    public static String item_6plug_times = "6plug_times";
    //3寸轴拔轴次数
    public static String item_3pull_times = "3pull_times";
    //6寸轴拔轴次数
    public static String item_6pull_times = "6pull_times";
    //穿轴总次数
    public static String item_plug_alltimes = "plug_alltimes";
    //拔轴总次数
    public static String item_pull_alltimes = "pull_alltimes";


    //1	全自动启动
    public static String item_to_command = "to_command";
    //0/1	穿轴/拔轴
    public static String item_to_type = "to_type";
    //3/6	轴尺寸
    public static String item_to_size = "to_size";


    private PlugPullDeviceSiteDeviceDriver driver;

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

    public int getItem_mode(){
        return this.getOpcIntegerValue(item_mode);
    } ;
    public int getItem_move(){
        return this.getOpcIntegerValue(item_move);
    } ;
    public int getItem_action(){
        return this.getOpcIntegerValue(item_action);
    };
    public int getItem_control(){
        return this.getOpcIntegerValue(item_control);
    } ;
    public int getItem_status(){
        return this.getOpcIntegerValue(item_status);
    } ;
    public int getItem_plug_finish(){
        return this.getOpcIntegerValue(item_plug_finish);
    } ;
    public int getItem_pull_finish(){
        return this.getOpcIntegerValue(item_pull_finish);
    } ;
    public int getItem_3plug_times(){
        return this.getOpcIntegerValue(item_3plug_times);
    } ;
    public int getItem_6plug_times(){
        return this.getOpcIntegerValue(item_6plug_times);
    } ;
    public int getItem_3pull_times(){
        return this.getOpcIntegerValue(item_3pull_times);
    } ;
    public int getItem_6pull_times(){
        return this.getOpcIntegerValue(item_6pull_times);
    } ;
    public int getItem_plug_alltimes(){
        return this.getOpcIntegerValue(item_plug_alltimes);
    } ;
    public int getItem_pull_alltimes(){
        return this.getOpcIntegerValue(item_pull_alltimes);
    } ;


    Boolean isonline;

    public int getOpcIntegerValue(String protocol) {
        Integer value = this.driver.getIntegeregerValue(protocol);
        if (value == null) {
            setIsonline(false);
        } else {
            setIsonline(true);
            return value;
        }
        return 0;

    }

    public float getOpcFloatValue(String protocol) {
        Float value = this.driver.getDoubleValue(protocol);
        if (value == null) {
            setIsonline(false);
        } else {
            setIsonline(true);
            return value;
        }
        return 0;

    }



    public static List<ItemDto> getReadableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_mode, "工作模式", "30243"));
        list.add(new ItemDto(item_action, "半自动/全自动", "30245"));
        list.add(new ItemDto(item_control, "远程控制", "30254"));
        list.add(new ItemDto(item_status, "状态", "30181"));
        list.add(new ItemDto(item_move, "机头上有轴", "30252"));
        list.add(new ItemDto(item_plug_finish, "穿轴完成", "30249"));
        list.add(new ItemDto(item_pull_finish, "拔轴完成", "30250"));
        list.add(new ItemDto(item_3plug_times, "3寸轴穿轴次数", "30231"));
        list.add(new ItemDto(item_6plug_times, "6寸轴穿轴次数", "30235"));
        list.add(new ItemDto(item_3pull_times, "3寸轴拔轴次数", "30233"));
        list.add(new ItemDto(item_6pull_times, "6寸轴拔轴次数", "30237"));
        list.add(new ItemDto(item_plug_alltimes, "穿轴总次数", "30239"));
        list.add(new ItemDto(item_pull_alltimes, "拔轴总次数", "30241"));

        return list;
    }

    public static List<ItemDto> getWriteableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "下发命令", "40246"));
        list.add(new ItemDto(item_to_type, "类型", "40244"));
        list.add(new ItemDto(item_to_size, "尺寸", "40247"));

        return list;
    }

    @Override
    public String toString() {
        return "";
    }

}

