import { post } from '@/store/utils/api'
import * as U from '@/store/utils/apiUrls'
import * as T from '@/store/utils/types'

export const loadBankList = ({ commit, getters }, countryId = null) => {
  let inputData = {
    country_id: countryId === null ? getters.getMemberDetails.country_id : countryId,
    relations: ['banks'],
  }
  return post(U.API_COUNTRY_RELATION, inputData).then(response => {
    if (response.status === 200) {
      var bankInfo = []
      response.data.banks.map(item => {
        bankInfo.push({ bankId: item.id, bankName: item.name, bankSwiftCode: item.swift_code })
      })
      commit(T.SET_BANK_LIST, bankInfo)
    }
  })
}
