//
//  OTError.h
//
//  Copyright (c) 2014 Tokbox, Inc. All rights reserved.
//

#define OT_SESSION_ERROR_DOMAIN @"OTSessionErrorDomain"
#define OT_PUBLISHER_ERROR_DOMAIN @"OTPublisherErrorDomain"
#define OT_SUBSCRIBER_ERROR_DOMAIN @"OTSubscriberErrorDomain"
#define OT_VIDEOKIT_ERROR_DOMAIN @"OTVideoKitErrorDomain"

/**
 * Enumerations of error code values used by 
 * <[OTSessionDelegate session:didFailWithError:]>.
 */
typedef NS_ENUM(int32_t, OTSessionErrorCode) {
    /** Ignore. Used internally. */
    OTSessionSuccess = 0,
    
    /** An invalid API key or token was provided */
    OTAuthorizationFailure = 1004,

    /** An invalid session ID was provided */
    OTErrorInvalidSession  = 1005,
    
    /** There was an error connecting to OpenTok services */
    OTConnectionFailed     = 1006,

    /** A parameter passed in to the request is null or invalid. */
    OTNullOrInvalidParameter = 1011,
    
    /** The session is not connected, and the requested action requires an
     active session connection */
    OTNotConnected  = 1010,
    
    /** A method has been invoked at an illegal or inappropriate time for this
     * session. For example, attempting to connect an already connected session
     * will return this error. */
    OTSessionIllegalState  = 1015,
    
    /** No messaging server is available for this session */
    OTNoMessagingServer     = 1503,
    
    /** A socket could not be opened to the messaging server. Check that
      outbound ports 443 and 8080 are accessible. */
    OTConnectionRefused     = 1023,
    
    /** The connection timed out while attempting to get the session's state */
    OTSessionStateFailed    = 1020,
    
    /** A session with the
     * [media mode](http://tokbox.com/opentok/tutorials/create-session/#media-mode)
     * set to routed can only have two participants. */
    OTP2PSessionMaxParticipants = 1403,
    
    /**  The connection timed out while attempting to connect to the session. */
    OTSessionConnectionTimeout  = 1021,
    
    /** Thread dispatch failure, out of memory, parse error, etc. */
    OTSessionInternalError   = 2000,
    
    /** You attempted to send a signal with an invalid type. */
    OTSessionInvalidSignalType = 1461,
    
    /** You attempted to send a signal with a data string that is greater than
     the maximum length (8KB). */
    OTSessionSignalDataTooLong = 1413,
    
    /** Unable to force disconnect, perhaps because the client's capabilities are limited. */
    OTSessionUnableToForceDisconnect = 1520,
    
    /** Unable to force mute, perhaps because the client's capabilities are limited. */
    OTSessionUnableToForceMute = 1540,
    
    /** Unable to send signal, perhaps because the client's capabilities are limited
     (e.g., a publisher-only token). */
    OTSessionUnableToSendSignal = 1550,
    
    /** The connection to the OpenTok messaging server was dropped.. */
    OTConnectionDropped = 1022,
    
    /**
     * The subscriber is unknown to this session. This is usually the result of
     * attempting to unsubscribe a subscriber that is not associated with the
     * session.
     */
    OTSessionSubscriberNotFound = 1112,
    
    /** 
     * The publisher is unknown to this session. This is usually the result of
     * attempting to unpublish a publisher that is not associated with the
     * session.
     */
    OTSessionPublisherNotFound = 1113,
    
    /**
     * Unable to connect to the session. Terms of service violation: export compliance.
     */
    OTSessionBlockedCountry = 1026,
    
    /**
     * The client tried to connect to a session that has exceeded the limit for
     * simultaneous connections.
     */
    OTSessionConnectionLimitExceeded = 1027,

	/**
     * Tried to join an end-to-end encrypted session without an encryption secret
     */
    OTSessionEncryptionSecretMissing = 6000,
	
	/**
     * Tried to set an invalid encryption secret
     */
    OTSessionInvalidEncryptionSecret = 6004,
};

/**
 * Enumerations of error code values used by
 * <[OTPublisherKitDelegate publisher:didFailWithError:]>.
 */
typedef NS_ENUM(int32_t, OTPublisherErrorCode) {
    /** Ignore. Used internally. */
    OTPublisherSuccess = 0,
    
    /** Attempting to publish or set captions to a disconnected session. */
    OTSessionDisconnected = 1010,
    
    /** Thread dispatch failure, out of memory, etc. */
    OTPublisherInternalError = 2000,
    
    /** The publisher failed due to a WebRTC error. Check the error
     description for details. */
    OTPublisherWebRTCError = 1610,

    /** Internal error while encrypting a packet
     */
    OTPublisherEncryptionInternalError = 6001,
    
    /** Unsupported media codec for encryption
     */
    EncryptionUnsupportedCodec = 6005,

    /** The scalability mode string passed to setTargetScalabilityMode:error: is nil or not one of
     the supported values (L1T1–L3T3).
     */
    OTPublisherInvalidScalabilityMode = 6006,
};

/**
 * Enumerations of error code values used by
 * <[OTSubscriberKitDelegate subscriber:didFailWithError:]>.
 */
typedef NS_ENUM(int32_t, OTSubscriberErrorCode) {
    /** Ignore. Used internally. */
    OTSubscriberSuccess = 0,
    
    /** The subscriber timed out while attempting to connect to stream.
     Try subscribing again. */
    OTConnectionTimedOut = 1542,
    
    /** The subscriber or captions failed because the client is disconnected from the
     session. */
    OTSubscriberSessionDisconnected = 1010,
    
    /** The subscriber failed due to a WebRTC error. Check the error
     description for details. */
    OTSubscriberWebRTCError = 1600,
    
    /** The subscriber failed due to the stream being missing. This can
     happen if the subscriber is created at the same time the stream is
     removed from the session (eg. as a result of 
     <[OTSession unpublish:error:]>). 
     */
    OTSubscriberServerCannotFindStream = 1604,
    
    /**
     * The client tried to subscriber to a stream in a session that has
     * exceeded the limit for simultaneous streams.
     */
    OTSubscriberStreamLimitExceeded = 1605,

    /** The OTSubscriber failed due to an internal error. */
    OTSubscriberInternalError = 2000,

    /** The peer connection is not yet created or connected. */
    OTSubsriberPeerConnectionNotConnected = 1606,

    /** Internal error while decrypting a packet
     */
    OTSubscriberDecryptionInternalError = 6002,

    /** Secret mismatch while decrypting a packet
     */
    EncryptionSecretMismatch = 6003,

    /** Unsupported media codec for decryption
     */
    DecryptionUnsupportedCodec = 6006,
};


/**
 * Defines errors for the OpenTok iOS SDK.
 *
 * See the documentation for the following constant enumerations, which define
 * the code values for OTError objects:
 *
 * * <OTPublisherErrorCode>
 * * <OTSessionErrorCode>
 * * <OTSubscriberErrorCode>
 */
@interface OTError : NSError

@end
