import apiClient from './client'
import type { 
  ApprovalRequest, 
  CreateApprovalRequest, 
  ReviewApprovalRequest,
  PaginatedResponse,
  PaginationParams 
} from '@/types'

export const approvalsApi = {
  async getAll(params?: PaginationParams & { status?: string }): Promise<PaginatedResponse<ApprovalRequest>> {
    const response = await apiClient.get<PaginatedResponse<ApprovalRequest>>('/approvals', { params })
    return response.data
  },

  async getById(id: number): Promise<ApprovalRequest> {
    const response = await apiClient.get<ApprovalRequest>(`/approvals/${id}`)
    return response.data
  },

  async create(data: CreateApprovalRequest): Promise<ApprovalRequest> {
    const response = await apiClient.post<ApprovalRequest>('/approvals', data)
    return response.data
  },

  async review(id: number, data: ReviewApprovalRequest): Promise<ApprovalRequest> {
    const response = await apiClient.post<ApprovalRequest>(`/approvals/${id}/review`, data)
    return response.data
  },

  async getPending(): Promise<ApprovalRequest[]> {
    const response = await apiClient.get<ApprovalRequest[]>('/approvals/pending')
    return response.data
  },

  async getMyRequests(): Promise<ApprovalRequest[]> {
    const response = await apiClient.get<ApprovalRequest[]>('/approvals/my-requests')
    return response.data
  }
}
