import Vue from 'vue'
import Vuex from 'vuex'
// import axios from 'axios'
import Crud from '../crud'

const model = (payload) => ({
  id: payload.id,
  folio: payload.folio,
  customer_id: payload.customer_id,
  details: payload.details,
  status: payload.status,
  status_display: payload.status_display,
  subtotal: payload.subtotal,
  total: payload.total
})

const detail = (payload) => ({
  quantity: parseInt(payload.quantity),
  unit_price: parseFloat(payload.unit_price).toFixed(2),
  total: 1
})
var crud = new Crud('PurchaseOrders', model, detail)

Vue.use(Vuex)

const state = {
  ...crud.state,
  purchaseOrders: [],
  purchaseOrder: {
    details: []
  },
  catalog: {
    customers: [],
    payment_methods: []
  }
}

const mutations = {
  ...crud.mutations
}

const actions = {
  ...crud.actions
}

const getters = {
  ...crud.getters,
  purchaseOrders: state => state.purchaseOrders,
  purchaseOrder: state => state.purchaseOrder
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
