/**
 * Copyright (c) 2010-2020 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */

 /* ***********************************************************
 * This file was automatically generated on 2022-01-03.      *
 *                                                           *
 * openHAB Bindings Version 2.0.0                            *
 *                                                           *
 * If you have a bugfix for this file and want to commit it, *
 * please fix the bug in the generator. You can find a link  *
 * to the generators git repository on tinkerforge.com       *
 *************************************************************/

package org.openhab.binding.tinkerforge.internal.device;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jdt.annotation.NonNull;
import org.openhab.binding.tinkerforge.internal.handler.DeviceHandler;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.binding.ThingActions;
import org.eclipse.smarthome.core.thing.binding.ThingActionsScope;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.types.RefreshType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.ActionOutput;
import org.openhab.core.automation.annotation.RuleAction;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import java.util.Map;
import java.util.HashMap;

import com.tinkerforge.TinkerforgeException;
import com.tinkerforge.BrickletEPaper296x128;

/**
 * Passes through actions of the E-Paper 296x128 Bricklet.
 * @author Erik Fleckstein - Initial contribution
 */
@ThingActionsScope(name = "tinkerforge")
@NonNullByDefault
public class BrickletEPaper296x128Actions implements ThingActions, IBrickletEPaper296x128Actions {

    private @Nullable DeviceHandler handler;

    @Override
    public void setThingHandler(@Nullable ThingHandler handler) { this.handler = (DeviceHandler) handler; }

    @Override
    public @Nullable ThingHandler getThingHandler() { return handler; }

    private static IBrickletEPaper296x128Actions invokeMethodOf(@Nullable ThingActions actions) {
        if (actions == null) {
            throw new IllegalArgumentException("actions cannot be null");
        }
        if (actions.getClass().getName().equals(BrickletEPaper296x128Actions.class.getName())) {
            if (actions instanceof IBrickletEPaper296x128Actions) {
                return (IBrickletEPaper296x128Actions) actions;
            } else {
                return (IBrickletEPaper296x128Actions) Proxy.newProxyInstance(IBrickletEPaper296x128Actions.class.getClassLoader(),
                        new Class[] { IBrickletEPaper296x128Actions.class }, (Object proxy, Method method, Object[] args) -> {
                            Method m = actions.getClass().getDeclaredMethod(method.getName(),
                                    method.getParameterTypes());
                            return m.invoke(actions, args);
                        });
            }
        }
        throw new IllegalArgumentException("Actions is not an instance of BrickletEPaper296x128Actions");
    }

        @Override
    @RuleAction(label = "Draw")
    public void brickletEPaper296x128Draw(
            ) throws TinkerforgeException {
        DeviceHandler h = handler;
        if(h == null) {
            return;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return;
        }
        dev.draw();
        
    }

    public static void brickletEPaper296x128Draw(@Nullable ThingActions actions) throws TinkerforgeException {
        invokeMethodOf(actions).brickletEPaper296x128Draw();
    }


    @Override
    @RuleAction(label = "Get Draw Status")
    public @ActionOutput(name = "drawStatus", type="int")
           Map<String, Object> brickletEPaper296x128GetDrawStatus(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        int value = dev.getDrawStatus();
        
        result.put("drawStatus", value);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128GetDrawStatus(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128GetDrawStatus();
    }

    @Override
    @RuleAction(label = "Write Black White")
    public void brickletEPaper296x128WriteBlackWhite(
            @ActionInput(name = "xStart") int xStart,
            @ActionInput(name = "yStart") int yStart,
            @ActionInput(name = "xEnd") int xEnd,
            @ActionInput(name = "yEnd") int yEnd,
            @ActionInput(name = "pixels") boolean[] pixels) throws TinkerforgeException {
        DeviceHandler h = handler;
        if(h == null) {
            return;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return;
        }
        dev.writeBlackWhite(xStart, yStart, xEnd, yEnd, pixels);
        
    }

    public static void brickletEPaper296x128WriteBlackWhite(@Nullable ThingActions actions, int xStart, int yStart, int xEnd, int yEnd, boolean[] pixels) throws TinkerforgeException {
        invokeMethodOf(actions).brickletEPaper296x128WriteBlackWhite(xStart, yStart, xEnd, yEnd, pixels);
    }


    @Override
    @RuleAction(label = "Read Black White")
    public @ActionOutput(name = "pixels", type="boolean[]")
           Map<String, Object> brickletEPaper296x128ReadBlackWhite(
            @ActionInput(name = "xStart") int xStart,
            @ActionInput(name = "yStart") int yStart,
            @ActionInput(name = "xEnd") int xEnd,
            @ActionInput(name = "yEnd") int yEnd) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        boolean[] value = dev.readBlackWhite(xStart, yStart, xEnd, yEnd);
        
        result.put("pixels", value);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128ReadBlackWhite(@Nullable ThingActions actions, int xStart, int yStart, int xEnd, int yEnd) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128ReadBlackWhite(xStart, yStart, xEnd, yEnd);
    }

    @Override
    @RuleAction(label = "Write Color")
    public void brickletEPaper296x128WriteColor(
            @ActionInput(name = "xStart") int xStart,
            @ActionInput(name = "yStart") int yStart,
            @ActionInput(name = "xEnd") int xEnd,
            @ActionInput(name = "yEnd") int yEnd,
            @ActionInput(name = "pixels") boolean[] pixels) throws TinkerforgeException {
        DeviceHandler h = handler;
        if(h == null) {
            return;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return;
        }
        dev.writeColor(xStart, yStart, xEnd, yEnd, pixels);
        
    }

    public static void brickletEPaper296x128WriteColor(@Nullable ThingActions actions, int xStart, int yStart, int xEnd, int yEnd, boolean[] pixels) throws TinkerforgeException {
        invokeMethodOf(actions).brickletEPaper296x128WriteColor(xStart, yStart, xEnd, yEnd, pixels);
    }


    @Override
    @RuleAction(label = "Read Color")
    public @ActionOutput(name = "pixels", type="boolean[]")
           Map<String, Object> brickletEPaper296x128ReadColor(
            @ActionInput(name = "xStart") int xStart,
            @ActionInput(name = "yStart") int yStart,
            @ActionInput(name = "xEnd") int xEnd,
            @ActionInput(name = "yEnd") int yEnd) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        boolean[] value = dev.readColor(xStart, yStart, xEnd, yEnd);
        
        result.put("pixels", value);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128ReadColor(@Nullable ThingActions actions, int xStart, int yStart, int xEnd, int yEnd) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128ReadColor(xStart, yStart, xEnd, yEnd);
    }

    @Override
    @RuleAction(label = "Fill Display")
    public void brickletEPaper296x128FillDisplay(
            @ActionInput(name = "color") int color) throws TinkerforgeException {
        DeviceHandler h = handler;
        if(h == null) {
            return;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return;
        }
        dev.fillDisplay(color);
        
    }

    public static void brickletEPaper296x128FillDisplay(@Nullable ThingActions actions, int color) throws TinkerforgeException {
        invokeMethodOf(actions).brickletEPaper296x128FillDisplay(color);
    }

    @Override
    @RuleAction(label = "Draw Text")
    public void brickletEPaper296x128DrawText(
            @ActionInput(name = "positionX") int positionX,
            @ActionInput(name = "positionY") int positionY,
            @ActionInput(name = "font") int font,
            @ActionInput(name = "color") int color,
            @ActionInput(name = "orientation") int orientation,
            @ActionInput(name = "text") String text) throws TinkerforgeException {
        DeviceHandler h = handler;
        if(h == null) {
            return;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return;
        }
        dev.drawText(positionX, positionY, font, color, orientation, text);
        
    }

    public static void brickletEPaper296x128DrawText(@Nullable ThingActions actions, int positionX, int positionY, int font, int color, int orientation, String text) throws TinkerforgeException {
        invokeMethodOf(actions).brickletEPaper296x128DrawText(positionX, positionY, font, color, orientation, text);
    }

    @Override
    @RuleAction(label = "Draw Line")
    public void brickletEPaper296x128DrawLine(
            @ActionInput(name = "positionXStart") int positionXStart,
            @ActionInput(name = "positionYStart") int positionYStart,
            @ActionInput(name = "positionXEnd") int positionXEnd,
            @ActionInput(name = "positionYEnd") int positionYEnd,
            @ActionInput(name = "color") int color) throws TinkerforgeException {
        DeviceHandler h = handler;
        if(h == null) {
            return;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return;
        }
        dev.drawLine(positionXStart, positionYStart, positionXEnd, positionYEnd, color);
        
    }

    public static void brickletEPaper296x128DrawLine(@Nullable ThingActions actions, int positionXStart, int positionYStart, int positionXEnd, int positionYEnd, int color) throws TinkerforgeException {
        invokeMethodOf(actions).brickletEPaper296x128DrawLine(positionXStart, positionYStart, positionXEnd, positionYEnd, color);
    }

    @Override
    @RuleAction(label = "Draw Box")
    public void brickletEPaper296x128DrawBox(
            @ActionInput(name = "positionXStart") int positionXStart,
            @ActionInput(name = "positionYStart") int positionYStart,
            @ActionInput(name = "positionXEnd") int positionXEnd,
            @ActionInput(name = "positionYEnd") int positionYEnd,
            @ActionInput(name = "fill") boolean fill,
            @ActionInput(name = "color") int color) throws TinkerforgeException {
        DeviceHandler h = handler;
        if(h == null) {
            return;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return;
        }
        dev.drawBox(positionXStart, positionYStart, positionXEnd, positionYEnd, fill, color);
        
    }

    public static void brickletEPaper296x128DrawBox(@Nullable ThingActions actions, int positionXStart, int positionYStart, int positionXEnd, int positionYEnd, boolean fill, int color) throws TinkerforgeException {
        invokeMethodOf(actions).brickletEPaper296x128DrawBox(positionXStart, positionYStart, positionXEnd, positionYEnd, fill, color);
    }

    @Override
    @RuleAction(label = "Set Update Mode")
    public void brickletEPaper296x128SetUpdateMode(
            @ActionInput(name = "updateMode") int updateMode) throws TinkerforgeException {
        DeviceHandler h = handler;
        if(h == null) {
            return;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return;
        }
        dev.setUpdateMode(updateMode);
        
    }

    public static void brickletEPaper296x128SetUpdateMode(@Nullable ThingActions actions, int updateMode) throws TinkerforgeException {
        invokeMethodOf(actions).brickletEPaper296x128SetUpdateMode(updateMode);
    }


    @Override
    @RuleAction(label = "Get Update Mode")
    public @ActionOutput(name = "updateMode", type="int")
           Map<String, Object> brickletEPaper296x128GetUpdateMode(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        int value = dev.getUpdateMode();
        
        result.put("updateMode", value);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128GetUpdateMode(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128GetUpdateMode();
    }


    @Override
    @RuleAction(label = "Get Display Type")
    public @ActionOutput(name = "displayType", type="int")
           Map<String, Object> brickletEPaper296x128GetDisplayType(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        int value = dev.getDisplayType();
        
        result.put("displayType", value);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128GetDisplayType(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128GetDisplayType();
    }


    @Override
    @RuleAction(label = "Get Display Driver")
    public @ActionOutput(name = "displayDriver", type="int")
           Map<String, Object> brickletEPaper296x128GetDisplayDriver(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        int value = dev.getDisplayDriver();
        
        result.put("displayDriver", value);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128GetDisplayDriver(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128GetDisplayDriver();
    }


    @Override
    @RuleAction(label = "Read UID")
    public @ActionOutput(name = "uid", type="long")
           Map<String, Object> brickletEPaper296x128ReadUID(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        long value = dev.readUID();
        
        result.put("uid", value);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128ReadUID(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128ReadUID();
    }


    @Override
    @RuleAction(label = "Get Chip Temperature")
    public @ActionOutput(name = "temperature", type="int")
           Map<String, Object> brickletEPaper296x128GetChipTemperature(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        int value = dev.getChipTemperature();
        
        result.put("temperature", value);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128GetChipTemperature(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128GetChipTemperature();
    }


    @Override
    @RuleAction(label = "Get Status LED Config")
    public @ActionOutput(name = "config", type="int")
           Map<String, Object> brickletEPaper296x128GetStatusLEDConfig(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        int value = dev.getStatusLEDConfig();
        
        result.put("config", value);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128GetStatusLEDConfig(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128GetStatusLEDConfig();
    }


    @Override
    @RuleAction(label = "Get SPITFP Error Count")
    public @ActionOutput(name = "errorCountAckChecksum", type="long")
           @ActionOutput(name = "errorCountMessageChecksum", type="long")
           @ActionOutput(name = "errorCountFrame", type="long")
           @ActionOutput(name = "errorCountOverflow", type="long")
           Map<String, Object> brickletEPaper296x128GetSPITFPErrorCount(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        BrickletEPaper296x128.SPITFPErrorCount value = dev.getSPITFPErrorCount();
        
        result.put("errorCountAckChecksum", value.errorCountAckChecksum);
        result.put("errorCountMessageChecksum", value.errorCountMessageChecksum);
        result.put("errorCountFrame", value.errorCountFrame);
        result.put("errorCountOverflow", value.errorCountOverflow);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128GetSPITFPErrorCount(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128GetSPITFPErrorCount();
    }

    @Override
    @RuleAction(label = "Reset")
    public void brickletEPaper296x128Reset(
            ) throws TinkerforgeException {
        DeviceHandler h = handler;
        if(h == null) {
            return;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return;
        }
        dev.reset();
        
    }

    public static void brickletEPaper296x128Reset(@Nullable ThingActions actions) throws TinkerforgeException {
        invokeMethodOf(actions).brickletEPaper296x128Reset();
    }


    @Override
    @RuleAction(label = "Get Identity")
    public @ActionOutput(name = "uid", type="String")
           @ActionOutput(name = "connectedUid", type="String")
           @ActionOutput(name = "position", type="char")
           @ActionOutput(name = "hardwareVersion", type="short[]")
           @ActionOutput(name = "firmwareVersion", type="short[]")
           @ActionOutput(name = "deviceIdentifier", type="int")
           Map<String, Object> brickletEPaper296x128GetIdentity(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletEPaper296x128Wrapper dev = ((@Nullable BrickletEPaper296x128Wrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        BrickletEPaper296x128.Identity value = dev.getIdentity();
        
        result.put("uid", value.uid);
        result.put("connectedUid", value.connectedUid);
        result.put("position", value.position);
        result.put("hardwareVersion", value.hardwareVersion);
        result.put("firmwareVersion", value.firmwareVersion);
        result.put("deviceIdentifier", value.deviceIdentifier);
        return result;
    }

    public static Map<String, Object> brickletEPaper296x128GetIdentity(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletEPaper296x128GetIdentity();
    }
}
