//
//  
//  UserCallData.swift
//  WoWonder
//
//  Created by Mohammed Hamad on 06/09/2022.
//  Copyright © 2022 ScriptSun. All rights reserved.
//
//
import Foundation
import UIKit

struct UserCallData: Codable {
    
    var data: UserCallModel?
    var user_id: String?
    var avatar: String?
    var name: String?
    
    enum CodingKeys: String, CodingKey {
        case data = "data"
        case user_id = "user_id"
        case avatar = "avatar"
        case name = "name"
    }
    
    init() {
        
    }
    
    init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        if let data = try? container.decode(UserCallModel.self, forKey: .data) {
            self.data = data
        }
        if let userID = try? container.decode(String.self, forKey: .user_id) {
            self.user_id = userID
        }
        if let avatar = try? container.decode(String.self, forKey: .avatar) {
            self.avatar = avatar
        }
        if let name = try? container.decode(String.self, forKey: .name) {
            self.name = name
        }
    }
    
    func getStringAnyData() -> [String: Any] {
        do {
            let encoder = JSONEncoder()
            let data = try encoder.encode(self)
            
            // Decode the Data into a [String: Any] dictionary using JSONSerialization
            if let dictionary = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
                // Now, 'dictionary' contains the model data as a dictionary
                print(dictionary)
                return dictionary
            }
        } catch {
            print("Error encoding/decoding the model: \(error)")
        }
        return ["": ""]
    }
    
}
