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

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_move = "move";
    public static String item_action = "action";
    public static String item_error = "error";
    public static String item_number = "number";
    public static String item_task = "task";


    public static String item_to_target = "to_target";//
    public static String item_to_command = "to_command";//
    public static String item_to_task = "to_task";//


    private PaintConveyorDeviceDriver driver;

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

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

    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_error() {
        return this.getOpcIntegerValue(item_error);
    }

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

    public int getItem_task() {
        return this.getOpcIntegerValue(item_task);
    }

    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 static List<ItemDto> getReadableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_heartbeat, "心跳", "D0000000"));
        list.add(new ItemDto(item_mode, "模式", "D0000004"));
        list.add(new ItemDto(item_move, "光电信号", "D0000008"));
        list.add(new ItemDto(item_action, "取放信号", "D0000012"));
        list.add(new ItemDto(item_error, "故障", "D0000016"));
        list.add(new ItemDto(item_number, "数量", "D0000020"));
        list.add(new ItemDto(item_task, "任务号", "D0000024"));

        return list;
    }

    public static List<ItemDto> getWriteableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "下发命令", "D00000102"));
        list.add(new ItemDto(item_to_target , "下发目标站", "D00000106"));
        list.add(new ItemDto(item_to_task, "任务号", "D00000110"));
        return list;
    }


}

