/**
 * 数据清理管理 API
 */
import { BaseService } from '../BaseService'
import type { BaseResponse } from '@/types/api'
import type {
  DataCleanupConfig,
  CreateDataCleanupConfigRequest,
  UpdateDataCleanupConfigRequest,
  DataCleanupLog,
  DataCleanupLogQueryParams,
  DataCleanupPreviewItem,
  DataCleanupProgress,
  TriggerDataCleanupRequest
} from '@/types/api/dataCleanup'

export class DataCleanupService extends BaseService {
  /**
   * 获取数据清理配置列表
   */
  static getDataCleanupConfigs(): Promise<BaseResponse<{ items: DataCleanupConfig[] }>> {
    return this.get<BaseResponse<{ items: DataCleanupConfig[] }>>('/api/admin/data-cleanup-configs')
  }

  /**
   * 获取数据清理配置详情
   */
  static getDataCleanupConfigById(id: number): Promise<BaseResponse<DataCleanupConfig>> {
    return this.get<BaseResponse<DataCleanupConfig>>(`/api/admin/data-cleanup-configs/${id}`)
  }

  /**
   * 创建数据清理配置
   */
  static createDataCleanupConfig(
    data: CreateDataCleanupConfigRequest
  ): Promise<BaseResponse<DataCleanupConfig>> {
    return this.post<BaseResponse<DataCleanupConfig>>('/api/admin/data-cleanup-configs', data)
  }

  /**
   * 更新数据清理配置
   */
  static updateDataCleanupConfig(
    id: number,
    data: UpdateDataCleanupConfigRequest
  ): Promise<BaseResponse<null>> {
    return this.put<BaseResponse<null>>(`/api/admin/data-cleanup-configs/${id}`, data)
  }

  /**
   * 删除数据清理配置
   */
  static deleteDataCleanupConfig(id: number): Promise<BaseResponse<null>> {
    return this.delete<BaseResponse<null>>(`/api/admin/data-cleanup-configs/${id}`)
  }

  /**
   * 获取数据清理日志列表
   */
  static getDataCleanupLogs(params?: DataCleanupLogQueryParams): Promise<
    BaseResponse<{
      items: DataCleanupLog[]
      page: number
      page_size: number
      total: number
      total_pages: number
    }>
  > {
    return this.get<
      BaseResponse<{
        items: DataCleanupLog[]
        page: number
        page_size: number
        total: number
        total_pages: number
      }>
    >('/api/admin/data-cleanup-logs', params)
  }

  /**
   * 预览待清理数据
   */
  static previewDataCleanup(): Promise<BaseResponse<{ items: DataCleanupPreviewItem[] }>> {
    return this.get<BaseResponse<{ items: DataCleanupPreviewItem[] }>>(
      '/api/admin/data-cleanup/preview'
    )
  }

  /**
   * 获取数据清理进度
   */
  static getDataCleanupProgress(): Promise<BaseResponse<DataCleanupProgress>> {
    return this.get<BaseResponse<DataCleanupProgress>>('/api/admin/data-cleanup/progress')
  }

  /**
   * 手动触发数据清理
   */
  static triggerDataCleanup(data?: TriggerDataCleanupRequest): Promise<BaseResponse<null>> {
    return this.post<BaseResponse<null>>('/api/admin/data-cleanup/trigger', data || {})
  }
}
