import { SetMetadata, createParamDecorator, ExecutionContext } from '@nestjs/common';
import type { AuthUser } from '@vihar/shared';

// Mark a route as public (skips JwtAuthGuard)
export const IS_PUBLIC_KEY = 'isPublic';
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);

// Captain-only routes
export const REQUIRES_CAPTAIN_KEY = 'requiresCaptain';
export const RequiresCaptain = () => SetMetadata(REQUIRES_CAPTAIN_KEY, true);

// Internal cron routes (shared secret instead of JWT)
export const IS_INTERNAL_KEY = 'isInternal';
export const Internal = () => SetMetadata(IS_INTERNAL_KEY, true);

export const CurrentUser = createParamDecorator(
  (_data: unknown, ctx: ExecutionContext): AuthUser => {
    const request = ctx.switchToHttp().getRequest();
    return request.user as AuthUser;
  },
);
