import { defineStore } from 'pinia'

import { getUserData } from "@/api/user";
import { toggleSendWithAD,setUserTpl } from "@/api";

export const useUserStore = defineStore('user', {
    state: () => {
        return {
            userData: {
                is_send_ad: 0,
                nc_template: 0,
                nfc_template: 0,
            },
        }
    },
    getters: {
    },
    actions: {
        async getUserData() {
            console.log('store get userData');
            var res = await getUserData();
            if (res.code === 200) {
                this.userData = res.data
            }
        },
        async setSendWithAd(payload){
            let res = await toggleSendWithAD(payload);

            if (res.code === 200) {
                this.userData.is_send_ad = payload
                return true;
            }
            return false;            
        },
        async setUserTpl(payload) {
            let res = await setUserTpl(payload);
            if (res.code === 200) {
                this.userData.nc_template = payload
                return true;
            }
            return false;
        },
    },
    persist: true
})