//
//  VivochaValues.h
//  ios-sdk
//
//  Created by Michael Siddi on 11/11/13.
//  Copyright (c) 2013 Vivocha Inc. All rights reserved.
//


#ifndef VivochaSDK_Constants_h
#define VivochaSDK_Constants_h
#define VIVOCHA_SDK_BASE_URL @"https://www.vivocha.com"
#endif


#ifndef VivochaSDK_Values_h
#define VivochaSDK_Values_h

#ifndef UIColorFromRGB
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#endif


static inline void dispatch_async_on_main_thread(dispatch_block_t block) {
    if (block) {
        [[NSOperationQueue mainQueue] addOperationWithBlock:block];
    }
}

//Notifications

///Notifies that the Vivocha SDK has started
static NSString *VivochaSDK_Notif_Start = @"VivochaSDK_Notif_Start";

///Notifies that the Vivocha SDK has stopped
static NSString *VivochaSDK_Notif_Stop = @"VivochaSDK_Notif_Stop";

///Notifies that at least an agent is available to take contacts
static NSString *VivochaSDK_Notif_AvailableAgents = @"VivochaSDK_Notif_AvailableAgents";

///Notifies that there is no agent available at the moment to take contacts
static NSString *VivochaSDK_Notif_UnavailableAgents = @"VivochaSDK_Notif_UnavailableAgents";

/**
    This is fired when a persistence from local or remote has been performed.
    The remote persistence can only happen when a Customer Token is set.
    In this case, if there is an active Conversation it will be returned and if it has an active contact,
    it is also resumed and the didResumeContactFromConversation boolean is set to true.
    If a local persistence has been performed, the didResumeContactFromConversation will be set to false.
    @param conversation the resumed conversation
    @param currentContact   the resumed contact, if any
    @param didResumeFromConversation   true if it was resumed from a conversation.
*/
static NSString *VivochaSDK_Notif_OnPersistence = @"VivochaSDK_Notif_OnPersistence";

///Notifies the result of the contact creation request
static NSString *VivochaSDK_Notif_CreateContactResult = @"VivochaSDK_Notif_CreateContactResult";

///Notifies that a message has been sent from the Customer to the Agent
static NSString *VivochaSDK_Notif_Contact_SentTextMessageResult = @"VivochaSDK_Notif_Contact_SentTextMessageResult";

///Notifies that an ack has been sent from the Customer to the Agent
static NSString *VivochaSDK_Notif_Contact_SentAckMessageResult = @"VivochaSDK_Notif_Contact_SentAckMessageResult";

///Notifies that a custom action has been sent from the App to the Agent Desktop
static NSString *VivochaSDK_Notif_Contact_DidSendCustomActionResult = @"VivochaSDK_Notif_Contact_DidSendCustomActionResult";

///Notifies that a message has been received from the Agent
static NSString *VivochaSDK_Notif_Contact_ReceivedTextMessage = @"VivochaSDK_Notif_Contact_ReceivedTextMessage";

///Notifies that a message has been read from the Agent
static NSString *VivochaSDK_Notif_Contact_ReceivedAckMessage = @"VivochaSDK_Notif_Contact_ReceivedAckMessage";

///Notifies that an attachment has been received
static NSString *VivochaSDK_Notif_Contact_ReceivedAttachment = @"VivochaSDK_Notif_Contact_ReceivedAttachment";

///Notifies that an Agent presence has been received
static NSString *VivochaSDK_Notif_Contact_ReceivedAgentPresence = @"VivochaSDK_Notif_Contact_ReceivedAgentPresence";

///Notifies that the Agent is typing
static NSString *VivochaSDK_Notif_Contact_AgentIsTyping = @"VivochaSDK_Notif_Contact_AgentIsTyping";

///Notifies that the agent closed the contact
static NSString *VivochaSDK_Notif_Contact_ReceivedTerminationEventFromOtherPeer = @"VivochaSDK_Notif_Contact_ReceivedTerminationEventFromOtherPeer";

///Notifies that the contact has been terminated
static NSString *VivochaSDK_Notif_Contact_Terminated = @"VivochaSDK_Notif_Contact_Terminated";

///Notifies that the user has pressed the End button on the Chat View and has terminated the contact
static NSString *VivochaSDK_Notif_Contact_UserDidTerminateChatView = @"VivochaSDK_Notif_Contact_UserDidTerminateChatView";

///Notifies that the chat view has been minimized.
static NSString *VivochaSDK_Notif_Contact_ChatViewMinimized = @"VivochaSDK_Notif_Contact_ChatViewMinimized";

///Notifies that a Screenshot session has been authorized by the user
static NSString *VivochaSDK_Notif_Contact_Screenshot_Authorized = @"VivochaSDK_Notif_Contact_Screenshot_Authorized";

///Notifies that a Screenshot session has been stopped by the user
static NSString *VivochaSDK_Notif_Contact_Screenshot_Stopped = @"VivochaSDK_Notif_Contact_Screenshot_Stopped";

//Translation keys

// -- Misc --

///Agent
static NSString *VivochaSDK_String_Agent = @"agent";

/// Waiting for an agent
static NSString *VivochaSDK_String_Agent_Waiting = @"agent_waiting_message";
/// Transfer in progress
static NSString *VivochaSDK_String_Agent_Waiting_Transfer = @"agent_waiting_transfer_message";

///is online
static NSString *VivochaSDK_String_Agent_Online = @"agent_online";
///is offline
static NSString *VivochaSDK_String_Agent_Offline = @"agent_offline";

///Live help
static NSString *VivochaSDK_String_UI_SideTab = @"sidetab_text";

// -- Chat View  --

/// Minimize on iPad
static NSString *VivochaSDK_String_UI_Btn_Minimize = @"button_minimize";

/// Back on iPhone
static NSString *VivochaSDK_String_UI_Btn_Back = @"button_back";

/// Close
static NSString *VivochaSDK_String_UI_Btn_Close = @"button_close";

/// Send
static NSString *VivochaSDK_String_UI_Btn_Send = @"button_send";

/// OK
static NSString *VivochaSDK_String_UI_Alert_Btn_OK = @"button_ok";

/// No
static NSString *VivochaSDK_String_UI_Alert_Btn_NO = @"button_no";

///Cancel
static NSString *VivochaSDK_String_UI_Alert_Btn_Cancel = @"button_cancel";

// -- Location  --

///Location Service Disabled
static NSString *VivochaSDK_String_UI_Alert_Location_Settings_Title = @"alert_location_settings_title";

/// To enable, please go to Settings -> Privacy -> Location and turn on Location Services for this app.
static NSString *VivochaSDK_String_UI_Alert_Location_Settings_Message = @"alert_location_settings_message";

/// Location Request
static NSString *VivochaSDK_String_UI_Alert_Location_Auth_Title = @"alert_location_request_title";

/// Do you want to allow the agent to see your location?
static NSString *VivochaSDK_String_UI_Alert_Location_Auth_Message = @"alert_location_request_message";

// -- Screenshot  --

/// Screenshot Request
static NSString *VivochaSDK_String_UI_Alert_Screenshot_Auth_Title = @"alert_screenshot_request_title";

/// Do you want to allow the agent to see your screen?
static NSString *VivochaSDK_String_UI_Alert_Screenshot_Auth_Message = @"alert_screenshot_request_message";

// -- Contact Lifecycle --

/// The chat has been closed. Thank you.
static NSString *VivochaSDK_String_UI_Alert_Chat_Cleared_Message = @"alert_chat_cleared_message";

/// The chat is not currently available.
static NSString *VivochaSDK_String_UI_Alert_Chat_Unavailable_Message = @"alert_chat_unavailable_message";

/// Retry
static NSString *VivochaSDK_String_UI_Alert_Chat_Unavailable_Btn_OK = @"alert_chat_unavailable_button_ok";

/// End
static NSString *VivochaSDK_String_UI_Alert_Chat_Unavailable_Btn_Cancel = @"alert_chat_unavailable_button_cancel";

/// There was an error establishing the contact. Please try again later.
static NSString *VivochaSDK_String_UI_Alert_Contact_Creation_Failure_Message = @"alert_contact_creation_failure_message";

/// Sorry
static NSString *VivochaSDK_String_UI_Alert_Contact_Dissuasion_Title = @"alert_contact_dissuasion_title";

/// There are no available agents at the moment. Please try again later.
static NSString *VivochaSDK_String_UI_Alert_Contact_Dissuasion_Message = @"alert_contact_dissuasion_message";

// -- Media --
/// Incoming video call
static NSString *VivochaSDK_String_UI_Alert_Media_Incoming_Video_Title = @"alert_media_incoming_video_title";

/// The agent wants to start a video call
static NSString *VivochaSDK_String_UI_Alert_Media_Incoming_Video_Message = @"alert_media_incoming_video_message";

/// Incoming audio call
static NSString *VivochaSDK_String_UI_Alert_Media_Incoming_Audio_Title = @"alert_media_incoming_audio_title";

/// The agent wants to start an audio call
static NSString *VivochaSDK_String_UI_Alert_Media_Incoming_Audio_Message = @"alert_media_incoming_audio_message";

/// Accept
static NSString *VivochaSDK_String_UI_Alert_Media_OK = @"alert_media_incoming_media_ok";

/// No, thanks
static NSString *VivochaSDK_String_UI_Alert_Media_NO = @"alert_media_incoming_media_no";

/// Audio Only
static NSString *VivochaSDK_String_UI_Alert_Media_AudioOnly = @"alert_media_incoming_media_audio_only";

/// Rejected by the agent.
static NSString *VivochaSDK_String_UI_Media_AgentReject_Message = @"alert_media_incoming_media_agentrejected_message";

/// Audio call in progress.
static NSString *VivochaSDK_String_UI_Media_AudioInProgress_Message = @"alert_media_incoming_media_audioinprogress_message";

/// Tap to mute.
static NSString *VivochaSDK_String_UI_Media_AudioInProgress_Mute_Subtitle = @"banner_media_audioinprogress_mute_subtitle";

/// Tap to unmute.
static NSString *VivochaSDK_String_UI_Media_AudioInProgress_Unmute_Subtitle = @"banner_media_audioinprogress_unmute_subtitle";

/// An error has occured.
static NSString *VivochaSDK_String_UI_Media_Error_Message = @"alert_media_incoming_media_error_message";

/// You are sharing your screen
static NSString *VivochaSDK_String_UI_Media_Screenshot_Session_Active_Message = @"banner_media_screenshot_session_active_message";

/// Do you want to stop screen sharing?
static NSString *VivochaSDK_String_UI_Media_Screenshot_Session_Deactive_Message = @"alert_media_screenshot_session_deactive_message";

/// Waiting for the agent
static NSString *VivochaSDK_String_UI_Media_WaitingAgent_Message = @"alert_media_incoming_media_waitingagent_message";

/// Connecting...
static NSString *VivochaSDK_String_UI_Media_Connecting_Message = @"alert_media_incoming_media_connecting_message";

// -- Attachments --
/// Photo & Video Library
static NSString *VivochaSDK_String_UI_Attachment_CameraRoll_Button_Title = @"button_attachment_camera_roll";

/// Take Photo/Video
static NSString *VivochaSDK_String_UI_Attachment_CameraTakePhoto_Button_Title = @"button_attachment_camera_take";

/// Document
static NSString *VivochaSDK_String_UI_Attachment_Documents_Button_Title = @"button_attachment_documents";

/// Cancel
static NSString *VivochaSDK_String_UI_Attachment_Cancel_Button_Title = @"button_attachment_cancel";

/// Confirm message after attachment selection
static NSString *VivochaSDK_String_UI_Attachment_Confirm_Message_Title = @"alert_attachment_confirm_message";

/// Do you want to try again?
static NSString *VivochaSDK_String_UI_Attachment_Resend_Alert_Title = @"button_attachment_resend_alert_title";

/// Resend
static NSString *VivochaSDK_String_UI_Attachment_Resend_Button_Title = @"button_attachment_resend_button_title";

/// Done
static NSString *VivochaSDK_String_UI_Attachment_Viewer_Close_Button_Title = @"button_attachment_viewer_close_button_title";

///Do you want to open the file?
static NSString *VivochaSDK_String_UI_Attachment_Open_Alert_Title = @"button_attachment_open_alert_title";


//Theme values

///Enabled value for a VivochaTheme option.
static NSString *const kVivochaThemeEnabledValue = @"ENABLED";

///Disabled value for a VivochaTheme option.
static NSString *const kVivochaThemeDisabledValue = @"DISABLED";

///Contact Color
typedef NS_ENUM(NSInteger, VivochaContactColor)  {
    VivochaContactColorWhite = 0,
    VivochaContactColorYellow = 1,
    VivochaContactColorOrange = 2,
    VivochaContactColorGreen = 3,
    VivochaContactColorBlue = 4,
    VivochaContactColorPurple = 5,
    VivochaContactColorRed = 6,
    VivochaContactColorNone = -1
};

///Side Tab Side
typedef NS_ENUM(NSInteger, VivochaPositionSide)  {
    
    ///Top of the screen
    VivochaPositionSideUp = 1,
    
    ///Bottom of the screen
    VivochaPositionSideDown = 2,
    
    ///Left side of the screen
    VivochaPositionSideLeft = 3,
    
    ///Right side of the screen
    VivochaPositionSideRight = 4
};

///Side Tab Position
typedef NS_ENUM(NSInteger, VivochaPosition) {
    
    ///If the side is left or right, it means the upper part of the screen,
    ///if the side is up or down it means the left part of the screen
    VivochaPositionTop = 1,
    
    ///Center of the side
    VivochaPositionMiddle = 2,
    
    ///If the side is left or right, it means the lower part of the screen,
    ///if the side is up or down it means the right part of the screen
    VivochaPositionBottom = 3,
};

///VivochaConnectionState
typedef NS_ENUM(NSInteger, VivochaConnectionState){
    
    ///Authentication failed, means that the contact has been closed from the Agent Desktop
    VivochaConnectionStateDidFailAuthentication = 1,
    ///The communication stream is connecting
    VivochaConnectionStateConnecting = 2,
    ///The communication stream is connected
    VivochaConnectionStateConnected = 3,
    ///The communication stream is disconnecting
    VivochaConnectionStateDisconnecting = 4,
    ///A timeout caused the communication stream to disconnect
    VivochaConnectionStateDisconnectedWithTimeout = 5,
    ///An error caused the communication stream to disconnect
    VivochaConnectionStateDisconnectedWithError = 6,
    ///The communication stream is disconnect
    VivochaConnectionStateDisconnected = 7,
    ///The contact is being transferred
    VivochaConnectionStateTransferring = 8,
};

///VivochaChatPresenceType
typedef NS_ENUM(NSInteger, VivochaChatPresenceType){
    
    ///The Agent joined the chat
    VivochaChatPresenceTypeOnline = 1,
    
    ///The Agent left the chat
    VivochaChatPresenceTypeGone = 2,
};

typedef NS_ENUM(NSInteger, VivochaContactMediaType) {
    VivochaContactMediaTypeChat     = 1 << 0,
    VivochaContactMediaTypeVideo    = 1 << 1,
    VivochaContactMediaTypeAudio    = 1 << 2,
};

///Start callback reason
typedef NS_ENUM(NSInteger, VivochaStartErrorReason)  {
    VivochaStartErrorReasonUnknown = 0,
    VivochaStartErrorReasonCampaignNotFound = 1,
    VivochaStartErrorReasonClosedOpeningHours = 2,
    VivochaStartErrorReasonWrongBundleId = 3
};

static inline uint32_t vivochaRandomWithOptions(int lowerbound, int upperbound){
    uint32_t randomValue = 0;
    
    int result = SecRandomCopyBytes(kSecRandomDefault, sizeof(int), (uint8_t*)&randomValue);
    
    if (result == errSecSuccess) {
        return randomValue % upperbound + lowerbound;
    }
    
    NSLog(@"Error while generating random number on vivochaRandomWithOptions(%d, %d)", lowerbound, upperbound);
    
    return 0;
}

static inline uint32_t vivochaRandomWithUpperBound(int upperbound){
    return vivochaRandomWithOptions(0, upperbound);
}

static inline uint32_t vivochaRandom(void){
    return vivochaRandomWithUpperBound(RAND_MAX);
}

#endif
