import { BadRequestException, HttpStatus } from '@nestjs/common';

/**
 * RFC 6749 §5.2 — `invalid_request`: the request is missing a required parameter,
 * includes an unsupported parameter value, repeats a parameter, includes multiple
 * credentials, utilizes more than one mechanism for authenticating the client,
 * or is otherwise malformed. Returned with HTTP 400.
 *
 * Used by the GraphQL resolver to reject payloads that select a grant type without
 * the fields that grant requires (e.g., PASSWORD without `username`/`password`,
 * REFRESH_TOKEN without `refreshToken`). The REST controller relies on body-shape
 * parsing for the equivalent check; the GraphQL resolver, receiving a typed input,
 * does the validation explicitly before dispatching to the handler.
 *
 * `statusCode` is included in the body so the NestJS Apollo driver's
 * `createTransformHttpErrorFn` sets `extensions.originalError`.
 */
export class InvalidRequestError extends BadRequestException {
  constructor() {
    super({ statusCode: HttpStatus.BAD_REQUEST, error: 'invalid_request' });
  }
}
