import http from "../http-common";

const getMessagesByGroupAndLanguage = (message_group, language) => {
  const params = {};
  if (message_group) {
    params.message_group = message_group;
  }
  if (language) {
    params.language = language;
  }
  return http.get('/messages/search', {
    params
  }); 
}

const createMessage = (data) => {
	return http.post('/messages', data);
};

const updateMessage = (id, data) => {
  return http.put(`/messages/${id}`, data);
}

const getMessage = (id) => {
  return http.get(`/messages/${id}`);
}

const getMessages = () => {
  return http.get(`/messages`);
}

const getSendMessageToken = () => {
  return http.get(`/message-tokens`)
}

const createMessageToken = (data) => {
  return http.post('/message-tokens', data);
}

const updateMessageToken = (id, data) => {
  return http.put(`/message-tokens/${id}`, data);
}

const sendMessage = (data) => {
  return http.post(`/messages/public/send`, data);
}

const bulkCreateMessages = (data) => {
  return http.post('/messages/bulk', data);
}

const getSentMessages = () => {
  return http.get(`/messages/sent-messages/all`);
}

// Custom Message Templates
const getCustomTemplates = () => {
  return http.get('/msg-custom-templates');
}

const createCustomTemplate = (data) => {
  return http.post('/msg-custom-templates', data);
}

const updateCustomTemplate = (id, data) => {
  return http.put(`/msg-custom-templates/${id}`, data);
}

const deleteCustomTemplate = (id) => {
  return http.delete(`/msg-custom-templates/${id}`);
}

export const MessageService = {
  getMessage,
  getMessages,
  updateMessage,
  createMessage,
  getMessagesByGroupAndLanguage,
  getSendMessageToken,
  updateMessageToken,
  createMessageToken,
  sendMessage,
  bulkCreateMessages,
  getSentMessages,
  getCustomTemplates,
  createCustomTemplate,
  updateCustomTemplate,
  deleteCustomTemplate
};
