import { createStore } from 'vuex';
import http from '../plugins/http';

export default createStore({
    state: {
        finished: false,
        userInfo: null,
        firstUrl: '',
        couponInfo: null
    },
    mutations: {
        setFinished(state, finished) {
            state.finished = finished;
        },
        setUserInfo(state, userInfo) {
            state.userInfo = userInfo;
        },
        setFirstUrl(state, url) {
            state.firstUrl = url;
        },
        setCouponInfo(state, couponInfo) {
            state.couponInfo = couponInfo;
        }
    },
    actions: {
        getUserInfo(context) {
            return http.http
                .get('/user/my')
                .then(res => {
                    context.commit('setUserInfo', res);
                    return Promise.resolve();
                })
                .catch(() => {
                    context.commit('setUserInfo', null);
                    return Promise.reject();
                });
        }
    },
    modules: {}
});
