import type { BaseResponse, PaginationParams } from './common'

export enum OrderPackageInvalidateTaskStatus {
  PENDING = 1,
  PROCESSING = 2,
  COMPLETED = 3,
  FAILED = 4
}

export interface OrderPackageInvalidateTaskQueryParams extends PaginationParams {
  status?: OrderPackageInvalidateTaskStatus
}

export interface OrderPackageInvalidateFailedItem {
  line: number
  order_no: string
  reason: string
}

export interface OrderPackageInvalidateTask {
  id: number
  task_no: string
  status: OrderPackageInvalidateTaskStatus
  status_text?: string
  status_name?: string
  total_count: number
  success_count: number
  fail_count: number
  skip_count?: number
  file_name: string
  file_key?: string
  voucher_keys?: string[]
  remark?: string
  creator_name?: string
  error_message?: string
  created_at: string
  started_at?: string | null
  completed_at?: string | null
}

export interface OrderPackageInvalidateTaskDetail extends OrderPackageInvalidateTask {
  failed_items?: OrderPackageInvalidateFailedItem[] | null
}

export interface OrderPackageInvalidateTaskListResponse {
  items: OrderPackageInvalidateTask[]
  page: number
  page_size: number
  total: number
  total_pages?: number
}

export interface CreateOrderPackageInvalidateTaskRequest {
  file_key: string
  file_name: string
  voucher_keys?: string[]
  remark?: string
}

export type OrderPackageInvalidateTaskListApiResponse =
  BaseResponse<OrderPackageInvalidateTaskListResponse>
export type OrderPackageInvalidateTaskDetailApiResponse =
  BaseResponse<OrderPackageInvalidateTaskDetail>
export type CreateOrderPackageInvalidateTaskApiResponse = BaseResponse<OrderPackageInvalidateTask>
