import Foundation

struct UserDataModel: Codable {
    
    let api_status : Int?
    let user_data : UserData?
    let followers : [UserData]?
    let following : [UserData]?
    let liked_pages : [String]?
    
    enum CodingKeys: String, CodingKey {
        case api_status = "api_status"
        case user_data = "user_data"
        case followers = "followers"
        case following = "following"
        case liked_pages = "liked_pages"
    }
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        api_status = try values.decodeIfPresent(Int.self, forKey: .api_status)
        user_data = try values.decodeIfPresent(UserData.self, forKey: .user_data)
        followers = try values.decodeIfPresent([UserData].self, forKey: .followers)
        following = try values.decodeIfPresent([UserData].self, forKey: .following)
        liked_pages = try values.decodeIfPresent([String].self, forKey: .liked_pages)
    }
    
}

class GetUserDataModel {
    
    struct LastLogin: Codable {
        
        var status : String?
        var country : String?
        var countryCode : String?
        var region : String?
        var regionName : String?
        var city : String?
        var zip : String?
        var lat : Double?
        var lon : Double?
        var timezone : String?
        var isp : String?
        var org : String?
        var asStr : String?
        var query : String?
            
        enum CodingKeys: String, CodingKey {
            case status = "status"
            case country = "country"
            case countryCode = "countryCode"
            case region = "region"
            case regionName = "regionName"
            case city = "city"
            case zip = "zip"
            case lat = "lat"
            case lon = "lon"
            case timezone = "timezone"
            case isp = "isp"
            case org = "org"
            case asStr = "as"
            case query = "query"
        }
        
        init(from decoder: Decoder) throws {
            let values = try decoder.container(keyedBy: CodingKeys.self)
            status = try values.decodeIfPresent(String.self, forKey: .status)
            country = try values.decodeIfPresent(String.self, forKey: .country)
            countryCode = try values.decodeIfPresent(String.self, forKey: .countryCode)
            region = try values.decodeIfPresent(String.self, forKey: .region)
            regionName = try values.decodeIfPresent(String.self, forKey: .regionName)
            city = try values.decodeIfPresent(String.self, forKey: .city)
            zip = try values.decodeIfPresent(String.self, forKey: .zip)
            lat = try values.decodeIfPresent(Double.self, forKey: .lat)
            lon = try values.decodeIfPresent(Double.self, forKey: .lon)
            timezone = try values.decodeIfPresent(String.self, forKey: .timezone)
            isp = try values.decodeIfPresent(String.self, forKey: .isp)
            org = try values.decodeIfPresent(String.self, forKey: .org)
            asStr = try values.decodeIfPresent(String.self, forKey: .asStr)
            query = try values.decodeIfPresent(String.self, forKey: .query)
        }
        
    }
    
}
