/**
 * 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.BrickletThermalImaging;

/**
 * Passes through actions of the Thermal Imaging Bricklet.
 * @author Erik Fleckstein - Initial contribution
 */
@ThingActionsScope(name = "tinkerforge")
@NonNullByDefault
public class BrickletThermalImagingActions implements ThingActions, IBrickletThermalImagingActions {

    private @Nullable DeviceHandler handler;

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

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

    private static IBrickletThermalImagingActions invokeMethodOf(@Nullable ThingActions actions) {
        if (actions == null) {
            throw new IllegalArgumentException("actions cannot be null");
        }
        if (actions.getClass().getName().equals(BrickletThermalImagingActions.class.getName())) {
            if (actions instanceof IBrickletThermalImagingActions) {
                return (IBrickletThermalImagingActions) actions;
            } else {
                return (IBrickletThermalImagingActions) Proxy.newProxyInstance(IBrickletThermalImagingActions.class.getClassLoader(),
                        new Class[] { IBrickletThermalImagingActions.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 BrickletThermalImagingActions");
    }

    
    @Override
    @RuleAction(label = "Get High Contrast Image")
    public @ActionOutput(name = "image", type="int[]")
           Map<String, Object> brickletThermalImagingGetHighContrastImage(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletThermalImagingWrapper dev = ((@Nullable BrickletThermalImagingWrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        int[] value = dev.getHighContrastImage();
        
        result.put("image", value);
        return result;
    }

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


    @Override
    @RuleAction(label = "Get Temperature Image")
    public @ActionOutput(name = "image", type="int[]")
           Map<String, Object> brickletThermalImagingGetTemperatureImage(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletThermalImagingWrapper dev = ((@Nullable BrickletThermalImagingWrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        int[] value = dev.getTemperatureImage();
        
        result.put("image", value);
        return result;
    }

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


    @Override
    @RuleAction(label = "Get Statistics")
    public @ActionOutput(name = "spotmeterStatistics", type="int[]")
           @ActionOutput(name = "temperatures", type="int[]")
           @ActionOutput(name = "resolution", type="int")
           @ActionOutput(name = "ffcStatus", type="int")
           @ActionOutput(name = "temperatureWarning", type="boolean[]")
           Map<String, Object> brickletThermalImagingGetStatistics(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletThermalImagingWrapper dev = ((@Nullable BrickletThermalImagingWrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        BrickletThermalImaging.Statistics value = dev.getStatistics();
        
        result.put("spotmeterStatistics", value.spotmeterStatistics);
        result.put("temperatures", value.temperatures);
        result.put("resolution", value.resolution);
        result.put("ffcStatus", value.ffcStatus);
        result.put("temperatureWarning", value.temperatureWarning);
        return result;
    }

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


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

        int value = dev.getResolution();
        
        result.put("resolution", value);
        return result;
    }

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


    @Override
    @RuleAction(label = "Get Spotmeter Config")
    public @ActionOutput(name = "regionOfInterest", type="int[]")
           Map<String, Object> brickletThermalImagingGetSpotmeterConfig(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletThermalImagingWrapper dev = ((@Nullable BrickletThermalImagingWrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        int[] value = dev.getSpotmeterConfig();
        
        result.put("regionOfInterest", value);
        return result;
    }

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


    @Override
    @RuleAction(label = "Get High Contrast Config")
    public @ActionOutput(name = "regionOfInterest", type="int[]")
           @ActionOutput(name = "dampeningFactor", type="int")
           @ActionOutput(name = "clipLimit", type="int[]")
           @ActionOutput(name = "emptyCounts", type="int")
           Map<String, Object> brickletThermalImagingGetHighContrastConfig(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletThermalImagingWrapper dev = ((@Nullable BrickletThermalImagingWrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        BrickletThermalImaging.HighContrastConfig value = dev.getHighContrastConfig();
        
        result.put("regionOfInterest", value.regionOfInterest);
        result.put("dampeningFactor", value.dampeningFactor);
        result.put("clipLimit", value.clipLimit);
        result.put("emptyCounts", value.emptyCounts);
        return result;
    }

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


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

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

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


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

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

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


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

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

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


    @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> brickletThermalImagingGetSPITFPErrorCount(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletThermalImagingWrapper dev = ((@Nullable BrickletThermalImagingWrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        BrickletThermalImaging.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> brickletThermalImagingGetSPITFPErrorCount(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletThermalImagingGetSPITFPErrorCount();
    }

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

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


    @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> brickletThermalImagingGetIdentity(
            ) throws TinkerforgeException {
        Map<String, Object> result = new HashMap<>();
        DeviceHandler h = handler;
        if(h == null) {
            return result;
        }
        
        @Nullable BrickletThermalImagingWrapper dev = ((@Nullable BrickletThermalImagingWrapper)h.getDevice());
        if(dev == null) {
            return result;
        }

        BrickletThermalImaging.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> brickletThermalImagingGetIdentity(@Nullable ThingActions actions) throws TinkerforgeException {
        return invokeMethodOf(actions).brickletThermalImagingGetIdentity();
    }
}
