import {
	getStore,
	setStore
} from '@/untils/store.js'
import {isGather} from '@/api/auth.js';
const authentication = {
	state: {
		// 实名认证
		realName: {},
		// 银行卡印证
		bankCard: {},
		// 采集签名
		autograph: getStore({
			name: 'autograph'
		}) || {},
	},
	getters: {},
	actions: {
		setRealName({
			commit,
			getters
		}, realName){
			commit('SET_REALNAME', realName);
		},
		setBankCard({
			commit,
			getters
		}, bankCard){
			commit('SET_BACKCARD', bankCard);
		},
		setAutograph({
			commit,
			getters
		}){
			return new Promise((resolve, reject) => {
				isGather().then((res) => {
					const data = res.data
					commit('SET_AUTOGRAPH', data);
					resolve(res.data)
				}).catch(reject)
			})
		},
		clearAuthenication(){
			commit('SET_REALNAME', '');
			commit('SET_BACKCARD', '');
			commit('SET_AUTOGRAPH', '');
		}
	},
	mutations: {
		SET_REALNAME: (state, realName) => {
			state.realName = realName;
			setStore({
				name: 'realName',
				content: realName,
				type: 'session'
			})
		},
		SET_BACKCARD: (state, bankCard) => {
			setStore({
				name: 'bankCard',
				content: bankCard,
				type: 'session'
			})
		},
		SET_AUTOGRAPH: (state, autograph) => {
			state.autograph = autograph;
			setStore({
				name: 'autograph',
				content: autograph,
				type: 'session'
			})
		}
	}
}
export default authentication