/**
 * Simulator Service
 * Handles simulator-related API calls
 */

import { apiClient } from '../client'

export interface Simulator {
  id: string
  file: string
  type: string
  description: string
  title: string
}

export interface CreateSimulatorRequest {
  file: string
  type: string
  description?: string
  title?: string
}

export interface CreateSimulatorResponse {
  simulator: Simulator
}

export interface GetSimulatorResponse {
  simulator: Simulator
}

export interface ListSimulatorsResponse {
  simulators: Simulator[]
}

export interface UpdateSimulatorRequest {
  id: string
  file?: string
  type?: string
  description?: string
  title?: string
}

export interface UpdateSimulatorResponse {
  simulator: Simulator
}

export interface DeleteSimulatorResponse {
  success: boolean
}

export const simulatorService = {
  /**
   * Create a new simulator
   */
  async createSimulator(data: CreateSimulatorRequest): Promise<Simulator> {
    const response = await apiClient.post<CreateSimulatorResponse>('/simulators', data)
    return response.simulator
  },

  /**
   * Get a simulator by ID
   */
  async getSimulator(id: string): Promise<Simulator> {
    const response = await apiClient.get<GetSimulatorResponse>(`/simulators/${id}`)
    return response.simulator
  },

  /**
   * List all simulators
   */
  async listSimulators(): Promise<Simulator[]> {
    const response = await apiClient.get<ListSimulatorsResponse>('/simulators')
    return response.simulators || []
  },

  /**
   * Update a simulator
   */
  async updateSimulator(data: UpdateSimulatorRequest): Promise<Simulator> {
    const { id, ...updateData } = data
    const response = await apiClient.put<UpdateSimulatorResponse>(`/simulators/${id}`, updateData)
    return response.simulator
  },

  /**
   * Delete a simulator
   */
  async deleteSimulator(id: string): Promise<boolean> {
    const response = await apiClient.delete<DeleteSimulatorResponse>(`/simulators/${id}`)
    return response.success
  }
}

