import { computed } from 'vue';
import { useAuthStore } from '@/modules/auth/auth.store';

export function useCurrentUser() {
  const authStore = useAuthStore();

  const currentUser = computed(() => authStore.currentUser);
  const isAuthenticated = computed(() => !!authStore.currentUser);
  const roles = computed(() => authStore.currentUser?.roles ?? []);

  function hasRole(role: string): boolean {
    return roles.value.includes(role);
  }

  function hasAnyRole(requiredRoles: string[]): boolean {
    return requiredRoles.some((r) => roles.value.includes(r));
  }

  return { currentUser, isAuthenticated, roles, hasRole, hasAnyRole };
}
