import {
	observable,
	action
} from 'mobx';

export default class AuthorityStore {
	constructor(api) {
		this.api = api;
	}

	@observable hasRight = false;
	@observable loading = true;

	@action fetchAuthority = (params = {}) => {
		return new Promise((resolve, reject) => {
			this.api(params).then(datas => {
				const {
					hasRight
				} = datas;

				this.hasRight = hasRight;
				this.loading = false;

				if (hasRight) {
					resolve();
				}else{
					reject();
				}
			}).catch(() => {
				reject();
			});
		})
	}
}