import api from 'src/api';

export const updateProvider = async (id, data) => {
  const { data: response } = await api.put(`/provider/${id}`, data);
  return response.payload;
};

export const updateProviderWithFiles = async (id, provider) => {
  const form = new FormData();

  Object.entries(provider).forEach(([key, value]) => {
    if (value !== null && value !== undefined) {
      form.append(key, value);
    }
  });

  form.append('_method', 'PUT');

  const { data: response } = await api.post(`/provider/${id}`, form);
  return response.payload;
};

export const getProviderDailyPriceMin = async () => {
  const { data: response } = await api.get('/provider/daily-price-min');
  return response.payload ?? response;
};
