import api from './axios'

export const formsApi = {
  list: params => api.get('admin/forms/all', { params }),
  add: payload => api.post('admin/forms/add', payload),
  get: (id, params = {}) => api.get(`admin/forms/${id}`, { params }),
  updatePreview: (id, language = 'en') =>
    api.get(`admin/forms/${id}/update-preview`, { params: { language } }),
  update: (id, payload) => api.put(`admin/forms/${id}`, payload),
  updateLegacy: (id, payload) => api.post(`admin/forms/${id}`, payload),
  delete: (id, params = {}) => api.delete(`admin/forms/${id}`, { params }),
  reorder: payload => api.post('admin/forms/reorder', payload),
  translate: payload => api.post('admin/translate', payload),
  adoptGlobal: (id, language) => api.post(`admin/forms/${id}/adopt-global`, { language }),
  resetGlobal: (id, language) => api.post(`admin/forms/${id}/reset-global`, { language }),
  updateLatestGlobal: (id, language) => api.post(`admin/forms/${id}/update-latest-global`, { language }),
  acceptGlobalFranchiseFormUpdate: (id, language) =>
    api.post(`api/franchise/forms/${id}/accept-global-update`, { language }),
  resetFranchiseFormToGlobal: (id, language) =>
    api.post(`api/franchise/forms/${id}/reset-to-global`, { language }),
  fetchFranchiseeSubmissions: params => api.get('admin/forms/franchisee-forms', { params }),
  fetchFranchiseeSubmissionEntries: franchiseeId => api.get(`admin/forms/franchisee-forms-entries/${franchiseeId}`),
}

export const fetchForms = formsApi.list
export const createForm = formsApi.add
export const updateForm = formsApi.update
export const deleteForm = formsApi.delete
export const getForm = formsApi.get
export const getFormUpdatePreview = formsApi.updatePreview
export const translateFormApi = formsApi.translate
export const reorderFormsApi = formsApi.reorder
export const adoptGlobalFormApi = formsApi.adoptGlobal
export const resetGlobalFormApi = formsApi.resetGlobal
export const updateLatestGlobalFormApi = formsApi.updateLatestGlobal
export const acceptGlobalFranchiseFormUpdateApi = formsApi.acceptGlobalFranchiseFormUpdate
export const resetFranchiseFormToGlobalApi = formsApi.resetFranchiseFormToGlobal
export const fetchFranchiseeSubmissions = formsApi.fetchFranchiseeSubmissions
export const fetchFranchiseeSubmissionEntries = formsApi.fetchFranchiseeSubmissionEntries
