import axios from 'axios'
import {
  result
} from 'lodash';

export default {
  namespaced: true,
  state: {
    restaurants: [],
    restaurant: {},
    tradingHour: {},
    tradingHours: []
  },
  mutations: {
    setRestaurants(state, restaurants) {
      state.restaurants = restaurants;
    },
    setRestaurant(state, restaurant) {
      state.restaurant = restaurant;
    },
    setTradingHours(state, thours) {
      state.tradingHours = thours;
    }
  },
  getters: {},
  actions: {
    getRestaurants({
      commit
    }) {
      axios
        .get('/api/restaurant/getrestaurants')
        .then(result => commit("setRestaurants", result.data));
    },
    getRestaurant({
      commit
    }, id) {
      axios
        .get(`/api/restaurant/${id}`)
        .then(result => commit("setRestaurant", result.data));
    },
    getTradingHours({
      commit
    }, id) {
      axios
        .get(`/api/restaurant/GetTradingHours/${id}`)
        .then(result => commit("setTradingHours", result.data));
    },
    updateRestaurant({
      commit
    }, restaurant) {
      axios
        .put('/api/Restaurant', restaurant)
        .then(result => commit("setRestaurant", restaurant))
    },
    removeTradingHours({
      commit
    }, id) {
      axios
        .delete(`/api/Restaurant/RemoveTradingHours/${id}`)
    }
  }
}
