import client from "./client"
import type { ApiResponse } from "../types"

export interface UpstreamActionLog {
  id: number
  user_id: number | null
  username?: string | null
  order_id: number | null
  order_no?: string | null
  order_refund_id: number | null
  instance_id: number | null
  cloud_server_id: number | null
  upstream_id: number | null
  action_type: string
  resource_type: string
  resource_id: string | null
  source: string
  status: "submitted" | "running" | "success" | "failed" | "no_task" | "manual_handled" | "ignored" | "superseded" | string
  upstream_task_id: number | null
  request_method: string | null
  request_path: string | null
  request_payload: unknown
  response_payload: unknown
  task_payload: unknown
  error_message: string | null
  remark: string | null
  attempt_count: number
  last_checked_at: string | null
  completed_at: string | null
  created_at: string | null
  updated_at: string | null
}

export function listInstanceActions(instanceId: number, limit = 50) {
  return client.get<ApiResponse<UpstreamActionLog[]>>(`/v1/instances/${instanceId}/actions`, {
    params: { limit },
  })
}
