import axiosClient from '../../config/axios'
import { isApiSuccess } from './../../helper'


export const load = ({ commit }) => {
  return axiosClient
    .get('dashboard')
    .then(response => {

      if (isApiSuccess(response)) {
        commit('SET_MERCHANTS', response.data.merchants)
        commit('SET_ANNOUNCEMENTS', response.data.announcements)
      }

      return Promise.resolve(response)
    }).catch(exception => {
      commit('SET_MERCHANTS', [])
      commit('SET_ANNOUNCEMENTS', [])
      console.log('Dashboard Data Load Exception: ', exception);
    })
}

export const approveChargebackRequest = ({ commit }, payload) => {
  return axiosClient
    .post('chargeback/approve', payload)
    .then(response => {
      return Promise.resolve(response)
    }).catch(exception => {
      console.log('Approve Chargeback Request Exception: ', exception);
    })
}

export const rejectChargebackRequest = ({ commit }, payload) => {
  return axiosClient
    .post('chargeback/reject', payload)
    .then(response => {
      return Promise.resolve(response)
    }).catch(exception => {
      console.log('Reject Chargeback Request Exception: ', exception);
    })
}

export const refundRequest = ({ commit }, payload) => {
  return axiosClient
    .post('refundrequest', payload,{
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
    .then(response => {
      return Promise.resolve(response)
    }).catch(exception => {
      console.log('Refund Request Exception: ', exception);
    })
}