//
//  CooperationAcquirerViewModel.swift
//  suixinkan
//
//  Created by Codex on 2026/6/29.
//

import Foundation
import Combine

/// 合作获客员列表 ViewModel。
@MainActor
final class CooperationAcquirerViewModel: ObservableObject {
    @Published var acquirers: [CooperativeSaler] = []
    @Published private(set) var hasLoadedOnce = false

    /// 重新加载当前门店下的合作获客员。
    func reload(api: CooperationOrderServing, storeId: Int?) async {
        do {
            let storeParam = storeId.flatMap { $0 > 0 ? $0 : nil }
            let data = try await api.cooperativeSalers(storeId: storeParam, page: 1, pageSize: 20)
            acquirers = data.list
        } catch {
            if !hasLoadedOnce {
                acquirers = []
            }
        }
        hasLoadedOnce = true
    }
}
