//
//  User.swift

//
//  Created by Leon on 2025/7/12.
//

import CodableWrappers
import Foundation
import UIKit

enum Sex: Int, Codable {
    case male = 0
    case female = 1
    case noncomfirming = 2

    var localizedText: String {
        switch self {
        case .male:
            return NSLocalizedString("Male", comment: "Gender: Male")
        case .female:
            return NSLocalizedString("Female", comment: "Gender: Female")
        case .noncomfirming:
            return NSLocalizedString("Nonconforming", comment: "Gender: Non-binary/Nonconforming")
        }
    }
    
    var icon: UIImage {
        switch self {
        case .male:
            return UIImage(named: "sex_male_flag")!
        case .female:
            return UIImage(named: "sex_female_flag")!
        case .noncomfirming:
            return UIImage(named: "sex_no_gender_flag")!
        }
    }
}

@objcMembers class User: NSObject, Codable {
    var nickname: String?
//    @CustomCodingKey("id")
    var userId: Int = 0
    var sex: Sex = .noncomfirming
//    var age: Int = 0
    var token: String?
    /// yyyy-mm-dd
    var birthday: Int64?
    /// 是否需要强制完善用户基础信息
    var cpUserInfo: Bool = false
    /// 头像
    var headImage: String?
    
    var thirdEmail: String?
    var thirdNickname: String?
    var thirdType : ThirdType?
    var idCard: String?
    /// 是否是会员
    var isMember: Bool?
    /// 已创建AI数量
    var createdAiCount: Int?
    /// 可创建AI数量
    var canCreateAiCount: Int?
    
    func canCreateAIRole()-> Bool{
        guard let created = createdAiCount, let totalCount = canCreateAiCount else{return false}
        return totalCount > created
    }
}

struct ThirdLoginResponse: Codable {
    var token: String?
}


struct UserCreateCountResponse: Codable{
    /// 免费创作次数
    var freeNum: Int?
    var usedFreeNum: Int?
    
    /// 会员赠送创作次数
    var memberNum: Int?
    var usedMemberNum:Int?
    
    /// 购买创作次数
    var buyNum: Int?
    var usedBuyNum: Int?
}
