import { business } from '@/services';
import { useModel } from '@umijs/max';

const useOssToken = () => {
	const { initialState, setInitialState } = useModel('@@initialState');

	const getOssToken = async () => {
		if (initialState?.ossToken) {
			return initialState.ossToken;
		}

		const ossTokenVOResponse = await business.material.ossToken();
		setInitialState({
			...initialState,
			ossToken: ossTokenVOResponse.data,
		});

		return ossTokenVOResponse.data;
	};

	return {
		getOssToken,
	};
};

export default useOssToken;
