import api from '@/utils/http'

/**
 * 获取待审核门店列表
 */
export function fetchPendingStoreAudits(
  params?: Partial<Api.StoreAudit.ListPendingStoreAuditsParams>
) {
  return api.get<Api.StoreAudit.PendingStoreAuditResponse>({
    url: '/api/admin/v1/platform/store-audits/pending',
    params
  })
}

/**
 * 获取审核统计
 */
export function fetchStoreAuditStatistics(params?: Api.StoreAudit.StoreAuditStatisticsParams) {
  return api.get<Api.StoreAudit.StoreAuditStatisticsDto>({
    url: '/api/admin/v1/platform/store-audits/statistics',
    params
  })
}

/**
 * 获取门店审核详情
 */
export function fetchStoreAuditDetail(storeId: string) {
  return api.get<Api.StoreAudit.StoreAuditDetailDto>({
    url: `/api/admin/v1/platform/store-audits/${storeId}`
  })
}

/**
 * 获取审核记录
 */
export function fetchStoreAuditRecords(
  storeId: string,
  params?: Api.StoreAudit.ListStoreAuditRecordsParams
) {
  return api.get<Api.Common.PageResult<Api.StoreAudit.StoreAuditRecordDto>>({
    url: `/api/admin/v1/platform/store-audits/${storeId}/records`,
    params
  })
}

/**
 * 审核通过
 */
export function fetchApproveStoreAudit(
  storeId: string,
  data: Api.StoreAudit.ApproveStoreAuditRequest
) {
  return api.post<Api.StoreAudit.StoreAuditActionResultDto>({
    url: `/api/admin/v1/platform/store-audits/${storeId}/approve`,
    data
  })
}

/**
 * 审核驳回
 */
export function fetchRejectStoreAudit(
  storeId: string,
  data: Api.StoreAudit.RejectStoreAuditRequest
) {
  return api.post<Api.StoreAudit.StoreAuditActionResultDto>({
    url: `/api/admin/v1/platform/store-audits/${storeId}/reject`,
    data
  })
}

/**
 * 强制关闭门店
 */
export function fetchForceCloseStore(storeId: string, data: Api.StoreAudit.ForceCloseStoreRequest) {
  return api.post<Api.StoreAudit.StoreAuditActionResultDto>({
    url: `/api/admin/v1/platform/store-audits/${storeId}/force-close`,
    data
  })
}

/**
 * 解除强制关闭
 */
export function fetchReopenStore(storeId: string, data: Api.StoreAudit.ReopenStoreRequest) {
  return api.post<Api.StoreAudit.StoreAuditActionResultDto>({
    url: `/api/admin/v1/platform/store-audits/${storeId}/reopen`,
    data
  })
}

/**
 * 获取资质预警列表（平台）
 */
export function fetchQualificationAlerts(
  params?: Partial<Api.Store.StoreQualificationAlertQueryParams>
) {
  return api.get<Api.Store.StoreQualificationAlertResultDto>({
    url: '/api/admin/v1/platform/store-qualifications/expiring',
    params
  })
}
