//
//  ChatGptModel.swift
//  WoWonder
//
//  Created by iMac on 10/06/25.
//  Copyright © 2025 ScriptSun. All rights reserved.
//


import Foundation

struct ChatGptModel: Codable {
    
    let id : String?
    let object : String?
    let created : Int?
    let model : String?
    let choices : [ChatGptChoices]?
    
    enum CodingKeys: String, CodingKey {
        case id = "id"
        case object = "object"
        case created = "created"
        case model = "model"
        case choices = "choices"
    }
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        id = try values.decodeIfPresent(String.self, forKey: .id)
        object = try values.decodeIfPresent(String.self, forKey: .object)
        created = try values.decodeIfPresent(Int.self, forKey: .created)
        model = try values.decodeIfPresent(String.self, forKey: .model)
        choices = try values.decodeIfPresent([ChatGptChoices].self, forKey: .choices)
    }
    
}

struct ChatGptChoices : Codable {
    
    let index : Int?
    let message : ChatGptMessage?
    
    enum CodingKeys: String, CodingKey {
        case index = "index"
        case message = "message"
    }
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        index = try values.decodeIfPresent(Int.self, forKey: .index)
        message = try values.decodeIfPresent(ChatGptMessage.self, forKey: .message)
    }
    
}

struct ChatGptMessage : Codable {
    
    let role : String?
    let content : String?
    
    enum CodingKeys: String, CodingKey {
        case role = "role"
        case content = "content"
    }
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        role = try values.decodeIfPresent(String.self, forKey: .role)
        content = try values.decodeIfPresent(String.self, forKey: .content)
    }
    
}

struct ChatGptErrorModel: Codable {
    let message: String?
    let type: String?
    let code: String?
}
