package org.etsi.its.uppertester;

import org.etsi.its.codec.TestAdapterMessageTypeEnum;

/**
 * This interface provides methods to support DENM upper tester
 */
public interface IDenmUpperTester extends IUpperTester {

    /**
     * Creates a new Denm event in SUT
     * @param   denmEvent   Denm event to be generated
     * @return  True if operation is successful, false otherwise
     */
    public boolean generateDenmEvent(DenmEvent denmEvent);

    /**
     * Creates a new Denm event in SUT
     * @param   denmEvent           Denm event to be generated
     * @param   trafficFlowEffect
     * @return  True if operation is successful, false otherwise
     */
    public boolean generateDenmEvent(DenmEvent denmEvent, short trafficFlowEffect);

    /**
     * Creates a new Denm event in SUT
     * @param   denmEvent       Denm event to be generated
     * @param   linkedDenmEvent Linked Denm event
     * @return  True if operation is successful, false otherwise
     */
    public boolean generateDenmEvent(DenmEvent denmEvent, DenmEvent linkedDenmEvent);

    /**
     * Creates a new Denm event in SUT
     * @param   denmEvent       Denm event to be generated
     * @param   expirationTime  Timestamp indicating event expiration in units of milliseconds, 6 byte
     * @return  True if operation is successful, false otherwise
     */
    public boolean generateDenmEvent(DenmEvent denmEvent, long expirationTime);

    /**
     * Creates a new Denm event in SUT
     * @param   denmEvent      Denm event to be generated
     * @param   type           Event type to be generated
     * @param   event          Event value
     * @return  True if operation is successful, false otherwise
     */
    public boolean generateDenmEvent(DenmEvent denmEvent, TestAdapterMessageTypeEnum type, int event);

    /**
     * Creates a new Denm event in SUT
     * @param   denmEvent       Denm event to be generated
     * @param   expirationTime  Timestamp indicating event expiration in units of milliseconds, 6 byte
     * @param   frequency       Transmission frequency in units of 0.1 Hz
     * @return  True if operation is successful, false otherwise
     */
    public boolean generateDenmEvent(DenmEvent denmEvent, long expirationTime, short frequency);

    /*
     *         -- whether the event is caused by the originator ITS station
            causeType   ENUMERATED { itsStation, geographicalRegion },
            -- whether the event is physicalling relevant to the  receiving ITS station.
            relevance ENUMERATED {physicallyRelevant, difficultDrivingConditions },
            -- whether the event is time critical road safety event, set to TRUE if it is the case.
            timeCriticality BOOLEAN,);
     */
    /**
     * Creates a new Denm event in SUT
     * @param   denmEvent       Denm event to be generated
     * @param   mobile          Indicates whether the evetn is mobile or not
     * @param   causeType       Whether the event is caused by the originator ITS station
     * @param   relevance       Whether the event is physically relevant to the  receiving ITS station
     * @param   timeCritical    Whether the event is time critical road safety event, set to TRUE if it is the case
     * @return  True if operation is successful, false otherwise
     */
    public boolean generateDenmEvent(DenmEvent denmEvent, boolean mobile, short causeType, short relevance, boolean timeCritical);
    

    /**
     * Cancels a Denm event in SUT
     * @param   denmEvent   Denm event to be cancelled
     * @param   actionId    Denm event's last actionId
     * @return  True if operation is successful, false otherwise
     */
    public boolean generateDenmEventCancellation(DenmEvent denmEvent, ActionId actionId);
    
    /**
     * Negates a Denm event in SUT
     * @param   denmEvent   Denm event to be negated
     * @param   actionId    Denm event's last actionId
     * @return  True if operation is successful, false otherwise
     */
    public boolean generateDenmEventNegation(DenmEvent denmEvent, ActionId actionId);
 
    /**
     *  Updates the expiryTime field of the DENM event referred by actionId
     * @param   denmEvent   Denm event to be negated
     *  @param  actionId    DENM event to be updated
     *  @param  expiryTime  New expiry time value
     *  @return True if operation is successful, false otherwise
     */    
    public boolean updateDenmEvent(DenmEvent denmEvent, ActionId actionId, long expiryTime);
 
    /**
     *  Checks that IUT transmits specific packet to its upper layer
     *  @param  denmPdu  Sent DENM packet
     *  @return True if operation is successful, false otherwise
     */    
    public boolean checkDenmEvent(byte[] denmPdu);
 
    /**
     * DENM event description
     */
    public class DenmEvent {
        
        /**
         * Constructor
         * @param cause     Event cause ID
         * @param subCause  Event sub-cause ID
         */
        public DenmEvent(short cause, short subCause) {
            this.cause = cause;
            this.subCause = subCause;
        }
        
        /**
         * Description of the direct cause for the event
         * 
         * See ETSI TS 102 637-3 - Clause 6.1.2 DENM situation container
         */
        public short cause;

        /**
         * Description of more detailed information for the direct cause
         * 
         * See ETSI TS 102 637-3 - Clause 6.1.2 DENM situation container
         */
        public short subCause;
    }
    
    /**
     * ActionId description
     */
    public class ActionId {
        
        /**
         * Constructor
         * @param stationId   Station ID
         * @param sequenceNo  Sequence number
         */
        public ActionId(int stationId, short sequenceNo) {
            this.stationId = stationId;
            this.sequenceNo = sequenceNo;
        }
        
        /**
         * Station ID
         */
        public int stationId;

        /**
         * Sequence number 
         */
        public short sequenceNo;
    }
}

