//
//  ChatRoleTagViewModel.swift
//  Visual_Novel_iOS
//
//  Created by mh on 2025/11/7.
//

import Foundation

struct RoleTagRequest: Codable {
    var limit = 20
    var name: String = ""
}

struct RoleTagModel: Codable {
    var total: Int = 0
    var rows: [RoleTagItem] = []
}

struct RoleTagItem: Codable {
    var id: String = ""
    var name: String = ""
}

class ChatRoleTagViewModel {
    
    func loadRoleTags(name: String, limit: Int = 20, completion: ((_ datas: RoleTagModel?) -> Void)?) {
        var req = RoleTagRequest()
        req.limit = limit
        req.name = name
        
        let params = req.toNonNilDictionary()
        
        RoleTagProvider.request(.tagList(params: params), modelType: RoleTagModel.self) { result in
            switch result {
            case .success(let model):
                // 如果返回的是单个 RoleListModel，将其包装成数组
                if let model = model {
                    completion?(model)
                } else {
                    completion?(nil)
                }
            case .failure(let failure):
                dlog("⛔️ 加载角色标签失败: \(failure)")
                completion?(nil)
            }
        }
    }
}
