import axios from 'axios';
import { restURL, novaPosthaApiURL } from '../baseURL';


export const getGoodsInGroup = (id, query) => (
    axios.get(`${restURL}/group/${id}`, { params: query })
);
export const getGoodsById = (id) => (
    axios.get(`${restURL}/product/${id}`)
);
export const getDynamicSearchLocationResult = citySearchString => (
    axios.post(`${novaPosthaApiURL}/AddressGeneral/getSettlements/`, citySearchString)
);
export const sendSignUpFormData = (signUpData) => (
    axios.post(`${restURL}/signUp`, signUpData)
);

export const sendAuthFormData = (authData) => (
    axios.post(`${restURL}/auth`, authData)
);

export const checkAuth = (token) => (
  axios.get(`${restURL}/checkedAuth`, {'headers': {'Auth': token}})
);

export const getPersonalUserData = (token) => (
  axios.get(`${restURL}/getPersonalData`, {'headers': {'Auth': token}})
);

export const updatePersonalData = (personalData, token) => (
  axios.post(`${restURL}/updatePersonalData`, personalData, {'headers': {'Auth': token}})
);

export const appendFavouriteGoods = (goodsId, token) => (
    axios.get(`${restURL}/appendFavouriteGoods/${goodsId}`, {'headers': {'Auth': token}})
);

export const getFavouriteGoods = (token) => (
    axios.get(`${restURL}/getFavouriteGoods`, {'headers': {"Auth": token}})
);

export const deleteFavouriteGoods = (goodsId, token) => (
  axios.get(`${restURL}/deleteFavouriteGoods/${goodsId}`, {'headers': {'Auth': token}})
);

export const getHistoryOrders = (token) => (
  axios.get(`${restURL}/getUserOrders`, {'headers': {'Auth': token}})
);

export const deleteOrder = (id, token) => (
  axios.get(`${restURL}/deleteOrder/${id}`, {'headers': {'Auth': token}})
);

export const issueOrder = (orderData, token) => (
  axios.post(`${restURL}/appendOrders`, orderData, token && {'headers': {'Auth': token}})
);

export const getAllOrders = (encryptedData, token) => (
    axios.post(`${restURL}/getAllOrders`, {encryptedData: encryptedData}, {'headers': {'Auth': token}})
);

export const getOrdersBySearchString = (token, encryptedData) => (
  axios.get(`${restURL}/getOrdersBySearchString`, {encryptedData: encryptedData}, {'headers': {'Auth': token}})
);

export const deleteOrderByAdmin = (orderId, token, encryptedData) => (
  axios.get(
      `${restURL}/deleteOrderByAdmin/${orderId}`,
      {'headers': {'Auth': token, 'encrypted': encryptedData}}
  )
);

export const appendOrderByAdmin = (encrypted, token) => (
    axios.post(`${restURL}/appendOrderByAdmin`, {encryptedData: encrypted}, {'headers': {'Auth': token}})
);

export const updateOrderByAdmin = (encrypted, token) => (
  axios.post(`${restURL}/updateOrderByAdmin`, {encryptedData: encrypted}, {'headers': {'Auth': token}})
);

export const dynamicSearchGoods = searchString => (
  axios.get(`${restURL}/dynamicSearchGoods/${searchString}`)
);

export const updateGoods = (encrypted, token) => (
    axios.post(`${restURL}/updateGoods`, {encryptedData: encrypted}, {'headers': {'Auth': token}})
);

export const deleteGoods = (goodsId, encryptedData, token) => (
    // console.log(goodsId)
  axios.get(
      `${restURL}/deleteSingleGoods/${goodsId}`,
      {'headers': {'Auth': token, 'encrypted': encryptedData}}
  )
);

export const appendPictureInGoodsAttribute = (formData, encrypted, token) => (
  axios.post(`${restURL}/appendPictureInAttribute`,
      formData,
      {'headers': {'Content-Type': 'multipart/form-data', 'Auth': token, 'encrypted': encrypted}}
    )
);

export const deletePictureInGoodsAttributes = (encrypted, token) => (
    axios.post(`${restURL}/deletePicture`, {encryptedData: encrypted}, {'headers': {'Auth': token}})
);

export const updateGoodsAttributes = (encrypted, token) => (
  axios.post(`${restURL}/updateGoodsAttributes`, {encryptedData: encrypted}, {'headers': {'Auth': token}})
);

export const deleteGoodsAttributes = (goodsAttributesId, encrypted, token) => (
  axios.get(
      `${restURL}/deleteGoodsAttribute/${goodsAttributesId}`,
      {'headers': {'Auth': token, 'encrypted': encrypted}}
  )
);

export const getFilterElements = (groupId) => (
  axios.get(`${restURL}/countFilterTypes/${groupId}`)
);