import type { HttpStatus } from "@nestjs/common";
import type { ErrorCodeType } from "@customer-portal/domain/common";

/**
 * Base class for all provider-specific errors.
 *
 * Carries structured metadata for error classification without string matching.
 * The UnifiedExceptionFilter detects subclasses and maps them to API responses.
 */
export abstract class BaseProviderError extends Error {
  abstract readonly provider: "whmcs" | "salesforce" | "freebit";
  abstract readonly providerCode: string;
  abstract readonly domainErrorCode: ErrorCodeType;
  abstract readonly httpStatus: HttpStatus;

  constructor(
    message: string,
    public readonly providerMessage: string,
    public override readonly cause?: unknown
  ) {
    super(message);
    this.name = this.constructor.name;
  }
}
