import { action, observable, makeObservable } from 'mobx'
import waterMarkService from './service'
import { BaseStore } from '@zenview/micro-basic-library';
let loadedWaterMake = false

class WaterMakeDomStore {
	constructor() {
		makeObservable(this)
	}
	@observable state = {
		rules: [],
		isCompulsory: 1
	}
	@action
	async loadState (refresh) {
		if (loadedWaterMake && !refresh) return
		loadedWaterMake = true
		try {
			const res = await waterMarkService.getWaterMark({ operationId: BaseStore.app.appInfo.id })
			const rules = res.data.watermarkRulesList
			const isCompulsory = res.data.isCompulsory
			this.state.rules = rules
			this.state.isCompulsory = isCompulsory
			return Promise.resolve({ rules, isCompulsory })
		} catch (error) {
			return Promise.reject(error)
		}
	}
}
export default new WaterMakeDomStore()