//
//  OperatingAreaAPI.swift
//  suixinkan
//
//  Created by Codex on 2026/6/25.
//

import Foundation
import Combine

/// 运营区域服务协议，定义店铺和景区管理员两类围栏数据接口。
@MainActor
protocol OperatingAreaServing {
    func storeBusinessArea(storeId: Int) async throws -> ListPayload<OperatingAreaItem>
    func scenicAdminBusinessArea(scenicId: Int) async throws -> ListPayload<OperatingAreaItem>
}

@MainActor
/// 运营区域 API，封装运营区域只读围栏接口。
final class OperatingAreaAPI {
    private let client: APIClient

    /// 初始化运营区域 API，并注入共享网络客户端。
    init(client: APIClient) {
        self.client = client
    }

    /// 获取当前店铺的运营区域围栏。
    func storeBusinessArea(storeId: Int) async throws -> ListPayload<OperatingAreaItem> {
        try await client.send(
            APIRequest(
                method: .get,
                path: "/api/app/store/business-area",
                queryItems: [URLQueryItem(name: "store_id", value: String(storeId))]
            )
        )
    }

    /// 获取景区管理员视角下的运营区域围栏。
    func scenicAdminBusinessArea(scenicId: Int) async throws -> ListPayload<OperatingAreaItem> {
        try await client.send(
            APIRequest(
                method: .get,
                path: "/api/app/scenic-admin/business-area",
                queryItems: [URLQueryItem(name: "scenic_id", value: String(scenicId))]
            )
        )
    }
}

extension OperatingAreaAPI: OperatingAreaServing {}
