/**
 * 代理系列授权 API 服务
 */

import { BaseService } from '../BaseService'
import type {
  ShopSeriesGrantResponse,
  ShopSeriesGrantQueryParams,
  CreateShopSeriesGrantRequest,
  UpdateShopSeriesGrantRequest,
  ManageGrantPackagesRequest,
  BaseResponse,
  PaginationResponse
} from '@/types/api'

export class ShopSeriesGrantService extends BaseService {
  /**
   * 获取代理系列授权分页列表
   * GET /api/admin/shop-series-grants
   * @param params 查询参数
   */
  static getShopSeriesGrants(
    params?: ShopSeriesGrantQueryParams
  ): Promise<PaginationResponse<ShopSeriesGrantResponse>> {
    return this.getPage<ShopSeriesGrantResponse>('/api/admin/shop-series-grants', params)
  }

  /**
   * 创建代理系列授权
   * POST /api/admin/shop-series-grants
   * @param data 授权数据
   */
  static createShopSeriesGrant(
    data: CreateShopSeriesGrantRequest
  ): Promise<BaseResponse<ShopSeriesGrantResponse>> {
    return this.create<ShopSeriesGrantResponse>('/api/admin/shop-series-grants', data)
  }

  /**
   * 获取代理系列授权详情
   * GET /api/admin/shop-series-grants/{id}
   * @param id 授权ID
   */
  static getShopSeriesGrantDetail(id: number): Promise<BaseResponse<ShopSeriesGrantResponse>> {
    return this.getOne<ShopSeriesGrantResponse>(`/api/admin/shop-series-grants/${id}`)
  }

  /**
   * 更新代理系列授权
   * PUT /api/admin/shop-series-grants/{id}
   * @param id 授权ID
   * @param data 授权数据
   */
  static updateShopSeriesGrant(
    id: number,
    data: UpdateShopSeriesGrantRequest
  ): Promise<BaseResponse<ShopSeriesGrantResponse>> {
    return this.update<ShopSeriesGrantResponse>(`/api/admin/shop-series-grants/${id}`, data)
  }

  /**
   * 删除代理系列授权
   * DELETE /api/admin/shop-series-grants/{id}
   * @param id 授权ID
   */
  static deleteShopSeriesGrant(id: number): Promise<BaseResponse> {
    return this.remove(`/api/admin/shop-series-grants/${id}`)
  }

  /**
   * 管理代理系列授权的套餐
   * PUT /api/admin/shop-series-grants/{id}/packages
   * @param id 授权ID
   * @param data 套餐管理数据
   */
  static manageGrantPackages(
    id: number,
    data: ManageGrantPackagesRequest
  ): Promise<BaseResponse<ShopSeriesGrantResponse>> {
    return this.put<BaseResponse<ShopSeriesGrantResponse>>(
      `/api/admin/shop-series-grants/${id}/packages`,
      data
    )
  }
}
