/**
 * 套餐管理 API 服务
 */

import { BaseService } from '../BaseService'
import type {
  PackageResponse,
  PackageQueryParams,
  CreatePackageRequest,
  UpdatePackageRequest,
  UpdatePackageStatusRequest,
  UpdatePackageShelfStatusRequest,
  BaseResponse,
  PaginationResponse,
} from '@/types/api'

export class PackageManageService extends BaseService {
  /**
   * 获取套餐分页列表
   * GET /api/admin/packages
   * @param params 查询参数
   */
  static getPackages(params?: PackageQueryParams): Promise<PaginationResponse<PackageResponse>> {
    return this.getPage<PackageResponse>('/api/admin/packages', params)
  }

  /**
   * 创建套餐
   * POST /api/admin/packages
   * @param data 套餐数据
   */
  static createPackage(data: CreatePackageRequest): Promise<BaseResponse<PackageResponse>> {
    return this.create<PackageResponse>('/api/admin/packages', data)
  }

  /**
   * 获取套餐详情
   * GET /api/admin/packages/{id}
   * @param id 套餐ID
   */
  static getPackageDetail(id: number): Promise<BaseResponse<PackageResponse>> {
    return this.getOne<PackageResponse>(`/api/admin/packages/${id}`)
  }

  /**
   * 更新套餐
   * PUT /api/admin/packages/{id}
   * @param id 套餐ID
   * @param data 套餐数据
   */
  static updatePackage(
    id: number,
    data: UpdatePackageRequest
  ): Promise<BaseResponse<PackageResponse>> {
    return this.update<PackageResponse>(`/api/admin/packages/${id}`, data)
  }

  /**
   * 删除套餐
   * DELETE /api/admin/packages/{id}
   * @param id 套餐ID
   */
  static deletePackage(id: number): Promise<BaseResponse> {
    return this.remove(`/api/admin/packages/${id}`)
  }

  /**
   * 更新套餐状态
   * PUT /api/admin/packages/{id}/status
   * @param id 套餐ID
   * @param status 状态 (1:启用, 2:禁用)
   */
  static updatePackageStatus(id: number, status: number): Promise<BaseResponse> {
    const data: UpdatePackageStatusRequest = { status }
    return this.patch<BaseResponse>(`/api/admin/packages/${id}/status`, data)
  }

  /**
   * 更新套餐上架状态
   * PATCH /api/admin/packages/{id}/shelf
   * @param id 套餐ID
   * @param shelf_status 上架状态 (1:上架, 2:下架)
   */
  static updatePackageShelfStatus(id: number, shelf_status: number): Promise<BaseResponse> {
    const data: UpdatePackageShelfStatusRequest = { shelf_status }
    return this.patch<BaseResponse>(`/api/admin/packages/${id}/shelf`, data)
  }

  /**
   * 修改套餐零售价（代理）
   * PATCH /api/admin/packages/{id}/retail-price
   * @param id 套餐ID
   * @param retail_price 零售价（分）
   */
  static updateRetailPrice(id: number, retail_price: number): Promise<BaseResponse> {
    return this.patch<BaseResponse>(`/api/admin/packages/${id}/retail-price`, { retail_price })
  }
}
