import { request } from "./http"; export interface VehiclePhoto { file_name: string | null; file_url: string | null; mime_type: string | null; size: number | null; } export interface VehiclePrimaryUser { id: number; first_name: string; last_name: string; full_name: string; email: string | null; } export interface Vehicle { id: number; photo: VehiclePhoto; brand: string; model: string; registration_number: string; vehicle_type: "hearse" | "transport_vehicle" | "utility" | "sedan"; fuel_type: "diesel" | "petrol" | "electric" | "hybrid"; year: number | null; status: "active" | "maintenance" | "out_of_service"; notes: string | null; primary_user_id: number | null; primary_user?: VehiclePrimaryUser | null; created_at: string; updated_at: string; } export interface VehicleListResponse { data: Vehicle[]; meta: { current_page: number; last_page: number; per_page: number; total: number; }; status: string; } export interface VehicleResponse { data: Vehicle; message?: string; status?: string; } export interface CreateVehiclePayload { photo_file_name?: string | null; photo_file_url?: string | null; photo_mime_type?: string | null; photo_size?: number | null; brand: string; model: string; registration_number: string; vehicle_type?: "hearse" | "transport_vehicle" | "utility" | "sedan"; fuel_type?: "diesel" | "petrol" | "electric" | "hybrid"; year?: number | null; primary_user_id?: number | null; status?: "active" | "maintenance" | "out_of_service"; notes?: string | null; } export interface UpdateVehiclePayload extends Partial { id: number; } export const VehicleService = { async getAllVehicles(params?: { page?: number; per_page?: number; search?: string; status?: string; vehicle_type?: string; sort_by?: string; sort_direction?: string; }): Promise { return await request({ url: "/api/vehicles", method: "get", params, }); }, async getVehicle(id: number): Promise { return await request({ url: `/api/vehicles/${id}`, method: "get", }); }, async createVehicle(payload: CreateVehiclePayload): Promise { return await request({ url: "/api/vehicles", method: "post", data: payload, }); }, async updateVehicle(payload: UpdateVehiclePayload): Promise { const { id, ...updateData } = payload; return await request({ url: `/api/vehicles/${id}`, method: "put", data: updateData, }); }, async deleteVehicle( id: number ): Promise<{ message: string; status: string }> { return await request<{ message: string; status: string }>({ url: `/api/vehicles/${id}`, method: "delete", }); }, }; export default VehicleService;