import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { UserRole } from '../user/user-role.enum';

@Injectable()
export class AdminGuard implements CanActivate {
  canActivate(context: ExecutionContext): boolean {
    const request = context.switchToHttp().getRequest();
    const user = request.user;

    // Check if user exists and has admin privileges (Super Admin or Tenant Admin)
    return !!(
      user &&
      (user.role === UserRole.SUPER_ADMIN ||
        user.role === UserRole.TENANT_ADMIN ||
        user.isAdmin === true)
    );
  }
}