package org.etsi.its.uppertester.operator;

import org.etsi.common.ByteHelper;
import org.etsi.its.codec.TestAdapterMessageTypeEnum;
import org.etsi.its.uppertester.IBtpUpperTester;
import org.etsi.its.uppertester.ICamUpperTester;
import org.etsi.its.uppertester.IDenmUpperTester;
import org.etsi.its.uppertester.IGnUpperTester;

public class ItsUpperTester implements ICamUpperTester, IBtpUpperTester, IDenmUpperTester, IGnUpperTester {

    @Override
    public boolean changeCurvature(int curvature) {  
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please change curvature: " + curvature);
        gui.dispose();
        return res;
    }

    @Override
    public boolean changeHeading(int direction) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please change heading: " + direction);
        gui.dispose();
        return res;
    }

    @Override
    public boolean changePosition(int distance) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please change position: " + distance);
        gui.dispose();
        return res;
    }

    @Override
    public boolean changeSpeed(int variation) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please change speed: " + variation);
        gui.dispose();
        return res;
    }

    @Override
    public boolean checkLdm(byte[] camPdu) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please");
        gui.dispose();
        return res;
    }

    @Override
    public boolean initialize(final String settings) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please initialize SUT");
        gui.dispose();
        return res;
    }

    @Override
    public boolean uninitialize() {
        return true;
    }

    @Override
    public boolean setCrashSignal(boolean crashed) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set crash signal: " + crashed);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setDangerousGoodsStatus(int dangerousGoodsStatus) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set dangerous goods status: " + dangerousGoodsStatus);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setDistanceToStopLine(int distance) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set distance to stop line: " + distance);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setDoorStatus(byte doorStatus) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set door status: " + doorStatus);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setExteriorLightsStatus(byte lightStatus) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set exterior lights status: " + lightStatus);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setLengthWidthPrecision(boolean lengthWidthPrecision) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set length width precision: " + lengthWidthPrecision);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setLightBarStatus(short status) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set light bar status: " + status);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setOccupancy(int occupancy) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set occupancy: " + occupancy);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setPtLineDescription(String courseOfJourney, String lineRef, String routeRef) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please set PT line description:<br/>"
                + "course of journey => " + courseOfJourney + "<br/>"
                + "line ref => " + lineRef + "<br/>"
                + "route ref => " + routeRef + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean setScheduleDeviation(int delay) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set schedule deviation: " + delay);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setSireneStatus(short status) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set sirene status: " + status);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setTrafficLightPriority(short priority) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please set traffic light priority: " + priority);
        gui.dispose();
        return res;
    }

    @Override
    public boolean setTurnAdvice(int direction, int distance) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please set turn advice:<br/>"
                + "direction => " + direction + "<br/>"
                + "distance => " + distance + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateDenmEvent(DenmEvent denmEvent) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate DENM event:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateDenmEvent(DenmEvent denmEvent, short trafficFlowEffect) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate DENM event:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + "traffic flow effect => " + trafficFlowEffect + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateDenmEvent(DenmEvent denmEvent, TestAdapterMessageTypeEnum type, int event) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate DENM event:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + type.name() + " => " + event + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateDenmEvent(DenmEvent denmEvent, DenmEvent linkedDenmEvent) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate DENM event:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + "linked event => " + linkedDenmEvent.cause + ", " + linkedDenmEvent.subCause + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateDenmEvent(DenmEvent denmEvent, long expirationTime) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate DENM event:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + "expiration => " + expirationTime + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateDenmEvent(DenmEvent denmEvent, long expirationTime, short frequency) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate DENM event:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + "expiration => " + expirationTime + "<br/>"
                + "frequency => " + frequency + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateDenmEvent(DenmEvent denmEvent, boolean mobile, short causeType, short relevance, boolean timeCritical) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate DENM event:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + "mobile => " + mobile + "<br/>"
                + "cause type => " + causeType + "<br/>"
                + "relevance => " + relevance + "<br/>"
                + "time critical => " + timeCritical + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateDenmEventCancellation(DenmEvent denmEvent, ActionId actionId) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate DENM event cancellation:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + "stationId => " + actionId.stationId + "<br/>"
                + "sequenceNo => " + actionId.sequenceNo + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateDenmEventNegation(DenmEvent denmEvent, ActionId actionId) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate DENM event negation:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + "stationId => " + actionId.stationId + "<br/>"
                + "sequenceNo => " + actionId.sequenceNo + "<br/>"                
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean updateDenmEvent(DenmEvent denmEvent, ActionId actionId, long expiryTime) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please update DENM event:<br/>"
                + "cause => " + denmEvent.cause + "<br/>"
                + "subcause => " + denmEvent.subCause + "<br/>"
                + "stationId => " + actionId.stationId + "<br/>"
                + "sequenceNo => " + actionId.sequenceNo + "<br/>"
                + "expiryTime => " + expiryTime + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean checkDenmEvent(byte[] denmPdu) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean changePosition() {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("Please change SUT position");
        gui.dispose();
        return res;
    }

    @Override
    public boolean checkPacket(byte[] packet) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please check that packet is received by upper layer:<br/>"
                + "packet => " + ByteHelper.byteArrayToString(packet) + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateGeoAnycast(short shape, int latitude, int longitude, short distanceA, short distanceB, short angle, short lifetime, byte[] payload) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate a GeoAnycast message:<br/>"
                + "shape => " + shape + "<br/>"
                + "latitude => " + latitude + "<br/>"
                + "longitude => " + longitude + "<br/>"
                + "distanceA => " + distanceA + "<br/>"
                + "distanceB => " + distanceB + "<br/>"
                + "angle => " + angle + "<br/>"
                + "lifetime => " + lifetime + "<br/>"
                + "payload => " + ByteHelper.byteArrayToString(payload) + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateGeoBroadcast(short shape, int latitude, int longitude, short distanceA, short distanceB, short angle, short lifetime, byte[] payload) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate a GeoBroadcast message:<br/>"
                + "shape => " + shape + "<br/>"
                + "latitude => " + latitude + "<br/>"
                + "longitude => " + longitude + "<br/>"
                + "distanceA => " + distanceA + "<br/>"
                + "distanceB => " + distanceB + "<br/>"
                + "angle => " + angle + "<br/>"   
                + "lifetime => " + lifetime + "<br/>"
                + "payload => " + ByteHelper.byteArrayToString(payload) + "<br/>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateGeoUnicast(byte[] gnAddress, short lifetime, byte[] payload) {
        OperatorGUI gui = new OperatorGUI();
        lifetime = (lifetime == 0)?255:lifetime;
        String payloadStr = ByteHelper.byteArrayToString(payload);
        payloadStr = (payloadStr.equals(""))?"Any payload":payloadStr;
        boolean res = gui.pop("<html>Please generate a GeoUnicast message:<br/>"
                + "Destination => " + ByteHelper.byteArrayToString(gnAddress) + "<br/>"
                + "lifetime => " + lifetime + "<br/>"
                + "payload => " + payloadStr + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateShb(byte[] payload) {
        OperatorGUI gui = new OperatorGUI();
        String payloadStr = ByteHelper.byteArrayToString(payload);
        payloadStr = (payloadStr.equals(""))?"Any payload":payloadStr;
        boolean res = gui.pop("<html>Please generate a SHB message:<br/>"
                + "payload => " + payloadStr + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateTsb(byte[] payload, short nbHops) {
        OperatorGUI gui = new OperatorGUI();
        String payloadStr = ByteHelper.byteArrayToString(payload);
        payloadStr = (payloadStr.equals(""))?"Any payload":payloadStr;
        boolean res = gui.pop("<html>Please generate a TSB message:<br/>"
                + "payload => " + payloadStr + "<br/>"
                + "hops => " + nbHops + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean checkPayload(byte[] payload) {
        OperatorGUI gui = new OperatorGUI();
        String payloadStr = ByteHelper.byteArrayToString(payload);
        payloadStr = (payloadStr.equals(""))?"Any payload":payloadStr;
        boolean res = gui.pop("<html>Please check that packet is received by upper layer:<br/>"
                + "payload => " + payloadStr + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateBtpA(int destinationPort, int sourcePort) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate a BTP-A message:<br/>"
                + "destination port => " + destinationPort + "<br/>"
                + "source port => " + sourcePort + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

    @Override
    public boolean generateBtpB(int destinationPort, int destinationPortInfo) {
        OperatorGUI gui = new OperatorGUI();
        boolean res = gui.pop("<html>Please generate a BTP-B message:<br/>"
                + "destination port => " + destinationPort + "<br/>"
                + "destination port info => " + destinationPortInfo + "<br/>"
                + "</html>"
        );
        gui.dispose();
        return res;
    }

}
