//
/* NOTICE: All information contained herein is, and remains the property of Brightinsight Inc. or its customer.
The intellectual and technical concepts contained herein are proprietary to Brightinsight Inc. or its customer and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law.
Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained from Brightinsight Inc. or its customer. Access to the source code contained herein is hereby forbidden to anyone except current Brightinsight Inc. employees, managers or contractors who have executed
Confidentiality and Non-disclosure agreements explicitly covering such access.
*/
/**
* System Name : BISDKCore
* Component ID : BISDKLogEvent
* Description :
* Author: Arnold Dominguez
* Copyright © : Brightinsight, Inc.
* -----------------------
* Revision Change
* -----------------------
* Author            Date             Version       Change-Description
*========================================================================================================
*/

import UIKit
import Foundation

public struct BISDKLogEvent: Encodable {
    let event: BISDKLogEventID
    let type: BISDKLogEventType
    let date: Date
    let extras: [String:String]
    
    public init(event: BISDKLogEventID, type: BISDKLogEventType, date: Date, extras: [String:String]) {
        self.event = event
        self.type = type
        self.date = date
        self.extras = extras
    }

    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(event.rawValue, forKey: .event)
        try container.encode(type.rawValue, forKey: .type)
        try container.encode(timestamp, forKey: .timestamp)
        try container.encode(localTime,forKey: .localTime)
        try container.encode(extras, forKey: .extras)
    }
}
extension BISDKLogEvent {
    enum CommonKeys: String {
        case statusCode = "statusCode"
        case recordType = "recordType"
        case uploadRetries = "uploadRetries"
        case totalUploadRetries = "totalUploadRetries"
    }
}
private extension BISDKLogEvent {
    var timestamp: String {
        let dateFormatter = ISO8601DateFormatter()
        return dateFormatter.string(from: date)
    }
    var localTime: String {
        let formatterLocalTime = DateFormatter()
        formatterLocalTime.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
        return formatterLocalTime.string(from: date)
    }
    enum CodingKeys: String, CodingKey {
        case event
        case type
        case timestamp
        case localTime
        case extras
    }
}
