import { request } from '@umijs/max';

export const _postCoupon = (data: API.CreateCouponData) => {
  console.log('data==>   ', data);
  return request('/api/v1/admin/coupon', {
    method: 'POST',
    data,
  });
};

export const _getCoupon = () => {
  return request('/api/v1/admin/coupon/all', {
    method: 'GET',
  });
};

export const _getCouponSelection = () => {
  return request('/api/v1/admin/coupon/selection', {
    method: 'GET',
  });
};

export const _getBusinessInfo = () => {
  return request('/api/v1/admin/setting/business/info', {
    method: 'GET',
  });
};

export const _getPriceEvent = () => {
  return request('/api/v1/admin/setting/business/info', {
    method: 'GET',
  });
};

export const _putBusinessPrice = (data: API.PriceEvent) => {
  return request(`/api/v1/admin/setting/business/owl/time`, {
    method: 'PUT',
    data,
  });
};
export const _putBusinessActiveStatus = (data: { id: string; is_active: boolean }) => {
  return request(`/api/v1/admin/setting/price/event`, {
    method: 'PUT',
    data,
  });
};

export const _createPriceEvent = (data: API.PriceEvent) => {
  return request(`/api/v1/admin/setting/price/event`, {
    method: 'POST',
    data,
  });
};

export const _deletePriceEvent = (id: string) => {
  return request(`/api/v1/admin/setting/price/event/${id}`, {
    method: 'DELETE',
  });
};

export const _getPenalty = () => {
  return request('/api/v1/admin/setting/penalty', {
    method: 'GET',
  });
};

export const _putPenalty = (data: {
  overtime_penalty_fee_min: number;
  overtime_penalty_time_min: number;
}) => {
  return request('/api/v1/admin/setting/penalty', {
    method: 'PUT',
    data,
  });
};

export const _getAdvertiseInfo = () => {
  return request('/api/v1/admin/setting/advertise/info', {
    method: 'GET',
  });
};

export const _putAdvertiseActiveStatus = (data: { id: string; is_show: boolean }) => {
  return request(`/api/v1/admin/setting/advertise/status`, {
    method: 'PUT',
    data,
  });
};

export const _putAdvertiseMainStatus = (data: { id: string }) => {
  return request(`/api/v1/admin/setting/advertise/main/status`, {
    method: 'PUT',
    data,
  });
};

export const _deleteAdvertise = (id: string) => {
  return request(`/api/v1/admin/setting/advertise/${id}`, {
    method: 'DELETE',
  });
};

export const _createAdvertise = (data: API.CreateAdvertisement) => {
  const formData = new FormData();
  formData.append('title', data.title);
  formData.append('text', data.text);
  formData.append('image_url', data.image_url);
  formData.append('is_show', data.is_show.toString());
  formData.append('is_main', data.is_main.toString());
  return request(`/api/v1/admin/setting/advertise`, {
    method: 'POST',
    data: formData,
  });
};
