/**
 * 平台账号相关 API - 匹配后端实际接口
 *
 * @deprecated 此 API 已废弃，请使用统一的 AccountService 代替
 * @see AccountService - 统一账号管理接口 (/api/admin/accounts)
 *
 * 迁移说明：
 * - 所有账号类型统一使用 /api/admin/accounts 接口
 * - 通过 user_type 参数区分账号类型 (2=平台, 3=代理, 4=企业)
 * - 详见：docs/迁移指南.md
 */

import { BaseService } from '../BaseService'
import type {
  PlatformAccountResponse,
  PlatformAccountQueryParams,
  CreatePlatformAccountParams,
  UpdatePlatformAccountParams,
  ChangePlatformAccountPasswordParams,
  AssignRolesParams,
  UpdateAccountStatusParams,
  PlatformAccountRoleResponse,
  BaseResponse,
  PaginationResponse
} from '@/types/api'

export class PlatformAccountService extends BaseService {
  /**
   * 1. 获取平台账号列表
   * GET /api/admin/platform-accounts
   * @param params 查询参数
   */
  static getPlatformAccounts(
    params?: PlatformAccountQueryParams
  ): Promise<PaginationResponse<PlatformAccountResponse>> {
    return this.getPage<PlatformAccountResponse>('/api/admin/platform-accounts', params)
  }

  /**
   * 2. 新增平台账号
   * POST /api/admin/platform-accounts
   * @param data 账号数据
   */
  static createPlatformAccount(
    data: CreatePlatformAccountParams
  ): Promise<BaseResponse<PlatformAccountResponse>> {
    return this.post<BaseResponse<PlatformAccountResponse>>('/api/admin/platform-accounts', data)
  }

  /**
   * 3. 移除角色
   * DELETE /api/admin/platform-accounts/{account_id}/roles/{role_id}
   * @param accountId 账号ID
   * @param roleId 角色ID
   */
  static removeRoleFromPlatformAccount(accountId: number, roleId: number): Promise<BaseResponse> {
    return this.delete<BaseResponse>(`/api/admin/platform-accounts/${accountId}/roles/${roleId}`)
  }

  /**
   * 4. 删除平台账号
   * DELETE /api/admin/platform-accounts/{id}
   * @param id 账号ID
   */
  static deletePlatformAccount(id: number): Promise<BaseResponse> {
    return this.remove(`/api/admin/platform-accounts/${id}`)
  }

  /**
   * 5. 获取平台账号详情
   * GET /api/admin/platform-accounts/{id}
   * @param id 账号ID
   */
  static getPlatformAccountDetail(id: number): Promise<BaseResponse<PlatformAccountResponse>> {
    return this.getOne<PlatformAccountResponse>(`/api/admin/platform-accounts/${id}`)
  }

  /**
   * 6. 编辑平台账号
   * PUT /api/admin/platform-accounts/{id}
   * @param id 账号ID
   * @param data 更新数据
   */
  static updatePlatformAccount(
    id: number,
    data: UpdatePlatformAccountParams
  ): Promise<BaseResponse<PlatformAccountResponse>> {
    return this.put<BaseResponse<PlatformAccountResponse>>(
      `/api/admin/platform-accounts/${id}`,
      data
    )
  }

  /**
   * 7. 修改密码
   * PUT /api/admin/platform-accounts/{id}/password
   * @param id 账号ID
   * @param data 新密码
   */
  static changePlatformAccountPassword(
    id: number,
    data: ChangePlatformAccountPasswordParams
  ): Promise<BaseResponse> {
    return this.put<BaseResponse>(`/api/admin/platform-accounts/${id}/password`, data)
  }

  /**
   * 8. 获取账号角色
   * GET /api/admin/platform-accounts/{id}/roles
   * @param id 账号ID
   */
  static getPlatformAccountRoles(id: number): Promise<BaseResponse<PlatformAccountRoleResponse[]>> {
    return this.get<BaseResponse<PlatformAccountRoleResponse[]>>(
      `/api/admin/platform-accounts/${id}/roles`
    )
  }

  /**
   * 9. 分配角色
   * POST /api/admin/platform-accounts/{id}/roles
   * @param id 账号ID
   * @param data 角色ID列表
   */
  static assignRolesToPlatformAccount(id: number, data: AssignRolesParams): Promise<BaseResponse> {
    return this.post<BaseResponse>(`/api/admin/platform-accounts/${id}/roles`, data)
  }

  /**
   * 10. 启用/禁用账号
   * PUT /api/admin/platform-accounts/{id}/status
   * @param id 账号ID
   * @param data 状态
   */
  static updatePlatformAccountStatus(
    id: number,
    data: UpdateAccountStatusParams
  ): Promise<BaseResponse> {
    return this.put<BaseResponse>(`/api/admin/platform-accounts/${id}/status`, data)
  }
}
