import http from "../http-common";
const getAll = () => {
  return http.get("/vehicles");
};
const getAllActiveVehicles = () => {
  return http.get("/vehicles/active")
};
const updateVehicles = (id, data) => {
  return http.put(`/vehicles/${id}`, data)
};
const createNewVehicles = (data) => {
	return http.post('/vehicles', data);
};
const deleteVehicles = (id, data) => {
  return http.delete(`/vehicles/${id}`);
};
const getVehicle = (id) => {
  return http.get(`/vehicles/${id}`);
};

const convertToDate = (dateString) => {
  const [month, day, year] = dateString.split('/');
  return new Date(Number(year), Number(month)-1, Number(day))
}

const uploadVechileFile = (data, vehicleId, name, fileType, date) => {
  return http.post(`/files/upload-physical?objectId=${vehicleId}&name=${name}&fileType=${fileType}&model=vehicle&date=${date.getTime()}`, data)
}

const getAllVechileFiles = (vehicleId, name, fileType) => {
  return http.get(`/files/uploadedDocs/vehicle/${vehicleId}/type/${fileType}/name/${name}`)
}

const deleteVechileFile = (vehicleId, fileType, fileName) => {
  return http.post('/files/delete-physical', {
    model: 'vehicle',
    objectId: vehicleId,
    fileType,
    fileName
  });
}

export const VehicleService = {
  getAll,
  getAllActiveVehicles,
  updateVehicles,
  createNewVehicles,
  deleteVehicles,
  getVehicle,
  convertToDate,
  uploadVechileFile,
  getAllVechileFiles,
  deleteVechileFile
};
