/**
 * 运营商管理相关 API
 */

import { BaseService } from '../BaseService'
import type {
  Carrier,
  CarrierQueryParams,
  CreateCarrierParams,
  UpdateCarrierParams,
  UpdateCarrierStatusParams,
  BaseResponse,
  PaginationResponse
} from '@/types/api'

export class CarrierService extends BaseService {
  /**
   * 获取运营商列表
   * GET /api/admin/carriers
   * @param params 查询参数
   */
  static getCarriers(params?: CarrierQueryParams): Promise<PaginationResponse<Carrier>> {
    return this.getPage<Carrier>('/api/admin/carriers', params)
  }

  /**
   * 创建运营商
   * POST /api/admin/carriers
   * @param data 运营商数据
   */
  static createCarrier(data: CreateCarrierParams): Promise<BaseResponse<Carrier>> {
    return this.create<Carrier>('/api/admin/carriers', data)
  }

  /**
   * 更新运营商
   * PUT /api/admin/carriers/{id}
   * @param id 运营商ID
   * @param data 运营商数据
   */
  static updateCarrier(id: number, data: UpdateCarrierParams): Promise<BaseResponse<Carrier>> {
    return this.update<Carrier>(`/api/admin/carriers/${id}`, data)
  }

  /**
   * 删除运营商
   * DELETE /api/admin/carriers/{id}
   * @param id 运营商ID
   */
  static deleteCarrier(id: number): Promise<BaseResponse> {
    return this.remove(`/api/admin/carriers/${id}`)
  }

  /**
   * 获取运营商详情
   * GET /api/admin/carriers/{id}
   * @param id 运营商ID
   */
  static getCarrierDetail(id: number): Promise<BaseResponse<Carrier>> {
    return this.getOne<Carrier>(`/api/admin/carriers/${id}`)
  }

  /**
   * 更新运营商状态
   * PUT /api/admin/carriers/{id}/status
   * @param id 运营商ID
   * @param status 状态 (1:启用, 0:禁用)
   */
  static updateCarrierStatus(id: number, status: number): Promise<BaseResponse> {
    const data: UpdateCarrierStatusParams = { status }
    return this.update(`/api/admin/carriers/${id}/status`, data)
  }
}
