/**
 * 微信支付配置管理 API
 */

import { BaseService } from '../BaseService'
import type { BaseResponse } from '@/types/api'
import type {
  WechatConfig,
  WechatConfigQueryParams,
  WechatConfigListResponse,
  CreateWechatConfigRequest,
  UpdateWechatConfigRequest
} from '@/types/api/wechatConfig'

export class WechatConfigService extends BaseService {
  /**
   * 获取支付配置列表
   */
  static getWechatConfigs(
    params?: WechatConfigQueryParams
  ): Promise<BaseResponse<WechatConfigListResponse>> {
    return this.get<BaseResponse<WechatConfigListResponse>>('/api/admin/wechat-configs', params)
  }

  /**
   * 获取支付配置详情
   */
  static getWechatConfigById(id: number): Promise<BaseResponse<WechatConfig>> {
    return this.get<BaseResponse<WechatConfig>>(`/api/admin/wechat-configs/${id}`)
  }

  /**
   * 创建支付配置
   */
  static createWechatConfig(data: CreateWechatConfigRequest): Promise<BaseResponse<WechatConfig>> {
    return this.post<BaseResponse<WechatConfig>>('/api/admin/wechat-configs', data)
  }

  /**
   * 更新支付配置
   */
  static updateWechatConfig(
    id: number,
    data: UpdateWechatConfigRequest
  ): Promise<BaseResponse<WechatConfig>> {
    return this.put<BaseResponse<WechatConfig>>(`/api/admin/wechat-configs/${id}`, data)
  }

  /**
   * 删除支付配置
   */
  static deleteWechatConfig(id: number): Promise<BaseResponse<void>> {
    return this.delete<BaseResponse<void>>(`/api/admin/wechat-configs/${id}`)
  }

  /**
   * 激活支付配置
   */
  static activateWechatConfig(id: number): Promise<BaseResponse<WechatConfig>> {
    return this.post<BaseResponse<WechatConfig>>(`/api/admin/wechat-configs/${id}/activate`)
  }

  /**
   * 停用支付配置
   */
  static deactivateWechatConfig(id: number): Promise<BaseResponse<WechatConfig>> {
    return this.post<BaseResponse<WechatConfig>>(`/api/admin/wechat-configs/${id}/deactivate`)
  }

  /**
   * 获取当前生效的支付配置
   */
  static getActiveWechatConfig(): Promise<BaseResponse<WechatConfig>> {
    return this.get<BaseResponse<WechatConfig>>('/api/admin/wechat-configs/active')
  }
}
