import type { KbxWorkQueueResult } from '@kbx/contracts'
import { kbxApi } from '../../../http/generated/kbxApiClient'

export interface ClaimWorkItemsResponse {
  claimedCount: number
  skippedCount: number
}

export interface ResolveWorkItemsResponse {
  resolvedCount: number
  rejectedCount: number
}

export interface OperationsFilter {
  module?: string | null
  severity?: string | null
  status?: string | null
  owner?: string | null
  code?: string | null
  keyword?: string | null
  page: number
  pageSize: number
}

export const operationsApi = {
  search(filter: OperationsFilter) {
    return kbxApi.request<KbxWorkQueueResult>('common.operations.search', { query: filter })
  },
  claim(ids: string[]) {
    return kbxApi.request<ClaimWorkItemsResponse, { ids: string[] }>('common.operations.claim', { body: { ids } })
  },
  resolve(ids: string[], reason = '사용자 확인 완료') {
    return kbxApi.request<ResolveWorkItemsResponse, { ids: string[]; reason: string }>('common.operations.resolve', { body: { ids, reason } })
  },
  retry(id: string) {
    return kbxApi.request<unknown>('common.operations.retry', { path: { id } })
  },
}
