import api from './client'

export interface GlobalRenderPosition {
  id: string
  name: string
  rotation_x: number
  rotation_y: number
  rotation_z: number
  is_default: boolean
  sort_order: number
  focal_length_mm: number | null
  sensor_width_mm: number | null
  created_at: string
  updated_at: string
}

export interface GlobalRenderPositionCreate {
  name: string
  rotation_x?: number
  rotation_y?: number
  rotation_z?: number
  is_default?: boolean
  sort_order?: number
  focal_length_mm?: number | null
  sensor_width_mm?: number | null
}

export interface GlobalRenderPositionPatch {
  name?: string
  rotation_x?: number
  rotation_y?: number
  rotation_z?: number
  is_default?: boolean
  sort_order?: number
  focal_length_mm?: number | null
  sensor_width_mm?: number | null
}

export async function listGlobalRenderPositions(): Promise<GlobalRenderPosition[]> {
  const res = await api.get<GlobalRenderPosition[]>('/render-positions/global')
  return res.data
}

export async function createGlobalRenderPosition(body: GlobalRenderPositionCreate): Promise<GlobalRenderPosition> {
  const res = await api.post<GlobalRenderPosition>('/render-positions/global', body)
  return res.data
}

export async function updateGlobalRenderPosition(id: string, body: GlobalRenderPositionPatch): Promise<GlobalRenderPosition> {
  const res = await api.patch<GlobalRenderPosition>(`/render-positions/global/${id}`, body)
  return res.data
}

export async function deleteGlobalRenderPosition(id: string): Promise<void> {
  await api.delete(`/render-positions/global/${id}`)
}
