import { useCallback } from 'react';
import { usePersSDK } from '../providers/PersSDKProvider';
export const useUserStatus = () => {
    const { sdk, isInitialized, isAuthenticated } = usePersSDK();
    const getUserStatusTypes = useCallback(async () => {
        if (!isInitialized || !sdk) {
            throw new Error('SDK not initialized. Call initialize() first.');
        }
        try {
            const result = await sdk.userStatus.getUserStatusTypes();
            return result;
        }
        catch (error) {
            console.error('Failed to fetch user status types:', error);
            throw error;
        }
    }, [sdk, isInitialized]);
    const getEarnedUserStatus = useCallback(async () => {
        if (!isInitialized || !sdk) {
            throw new Error('SDK not initialized. Call initialize() first.');
        }
        if (!isAuthenticated) {
            throw new Error('SDK not authenticated. getEarnedUserStatus requires authentication.');
        }
        try {
            const result = await sdk.userStatus.getEarnedUserStatus();
            return result;
        }
        catch (error) {
            console.error('Failed to fetch earned user status:', error);
            throw error;
        }
    }, [sdk, isInitialized, isAuthenticated]);
    // Admin methods
    const createUserStatusType = useCallback(async (userStatusType) => {
        if (!isInitialized || !sdk) {
            throw new Error('SDK not initialized. Call initialize() first.');
        }
        try {
            const result = await sdk.userStatus.createUserStatusType(userStatusType);
            return result;
        }
        catch (error) {
            console.error('Failed to create user status type:', error);
            throw error;
        }
    }, [sdk, isInitialized]);
    return {
        getUserStatusTypes,
        getEarnedUserStatus,
        createUserStatusType,
        isAvailable: isInitialized && !!sdk?.userStatus,
    };
};
