// @ts-nocheck
// Code generated by protoc-gen-ts-server. DO NOT EDIT.
// source: worldmonitor/economic/v1/service.proto

export interface GetFredSeriesRequest {
  seriesId: string;
  limit: number;
}

export interface GetFredSeriesResponse {
  series?: FredSeries;
}

export interface FredSeries {
  seriesId: string;
  title: string;
  units: string;
  frequency: string;
  observations: FredObservation[];
}

export interface FredObservation {
  date: string;
  value: number;
}

export interface ListWorldBankIndicatorsRequest {
  indicatorCode: string;
  countryCode: string;
  year: number;
  pageSize: number;
  cursor: string;
}

export interface ListWorldBankIndicatorsResponse {
  data: WorldBankCountryData[];
  pagination?: PaginationResponse;
}

export interface WorldBankCountryData {
  countryCode: string;
  countryName: string;
  indicatorCode: string;
  indicatorName: string;
  year: number;
  value: number;
}

export interface PaginationResponse {
  nextCursor: string;
  totalCount: number;
}

export interface GetEnergyPricesRequest {
  commodities: string[];
}

export interface GetEnergyPricesResponse {
  prices: EnergyPrice[];
}

export interface EnergyPrice {
  commodity: string;
  name: string;
  price: number;
  unit: string;
  change: number;
  priceAt: number;
}

export interface GetMacroSignalsRequest {
}

export interface GetMacroSignalsResponse {
  timestamp: string;
  verdict: string;
  bullishCount: number;
  totalCount: number;
  signals?: MacroSignals;
  meta?: MacroMeta;
  unavailable: boolean;
}

export interface MacroSignals {
  liquidity?: LiquiditySignal;
  flowStructure?: FlowStructureSignal;
  macroRegime?: MacroRegimeSignal;
  technicalTrend?: TechnicalTrendSignal;
  hashRate?: HashRateSignal;
  priceMomentum?: PriceMomentumSignal;
  fearGreed?: FearGreedSignal;
}

export interface LiquiditySignal {
  status: string;
  value?: number;
  sparkline: number[];
}

export interface FlowStructureSignal {
  status: string;
  btcReturn5?: number;
  qqqReturn5?: number;
}

export interface MacroRegimeSignal {
  status: string;
  qqqRoc20?: number;
  xlpRoc20?: number;
}

export interface TechnicalTrendSignal {
  status: string;
  btcPrice?: number;
  sma50?: number;
  sma200?: number;
  vwap30d?: number;
  mayerMultiple?: number;
  sparkline: number[];
}

export interface HashRateSignal {
  status: string;
  change30d?: number;
}

export interface PriceMomentumSignal {
  status: string;
}

export interface FearGreedSignal {
  status: string;
  value?: number;
  history: FearGreedHistoryEntry[];
}

export interface FearGreedHistoryEntry {
  value: number;
  date: string;
}

export interface MacroMeta {
  qqqSparkline: number[];
}

export interface GetEnergyCapacityRequest {
  energySources: string[];
  years: number;
}

export interface GetEnergyCapacityResponse {
  series: EnergyCapacitySeries[];
}

export interface EnergyCapacitySeries {
  energySource: string;
  name: string;
  data: EnergyCapacityYear[];
}

export interface EnergyCapacityYear {
  year: number;
  capacityMw: number;
}

export interface GetBisPolicyRatesRequest {
}

export interface GetBisPolicyRatesResponse {
  rates: BisPolicyRate[];
}

export interface BisPolicyRate {
  countryCode: string;
  countryName: string;
  rate: number;
  previousRate: number;
  date: string;
  centralBank: string;
}

export interface GetBisExchangeRatesRequest {
}

export interface GetBisExchangeRatesResponse {
  rates: BisExchangeRate[];
}

export interface BisExchangeRate {
  countryCode: string;
  countryName: string;
  realEer: number;
  nominalEer: number;
  realChange: number;
  date: string;
}

export interface GetBisCreditRequest {
}

export interface GetBisCreditResponse {
  entries: BisCreditToGdp[];
}

export interface BisCreditToGdp {
  countryCode: string;
  countryName: string;
  creditGdpRatio: number;
  previousRatio: number;
  date: string;
}

export interface GetFredSeriesBatchRequest {
  seriesIds: string[];
  limit: number;
}

export interface GetFredSeriesBatchResponse {
  results: Record<string, FredSeries>;
  fetched: number;
  requested: number;
}

export interface ListGroceryBasketPricesRequest {
}

export interface ListGroceryBasketPricesResponse {
  countries: CountryBasket[];
  fetchedAt: string;
  cheapestCountry: string;
  mostExpensiveCountry: string;
  upstreamUnavailable: boolean;
  wowAvgPct: number;
  wowAvailable: boolean;
  prevFetchedAt: string;
}

export interface CountryBasket {
  code: string;
  name: string;
  currency: string;
  flag: string;
  totalUsd: number;
  fxRate: number;
  items: GroceryItemPrice[];
  wowPct: number;
}

export interface GroceryItemPrice {
  itemId: string;
  itemName: string;
  unit: string;
  localPrice: number;
  usdPrice: number;
  currency: string;
  sourceSite: string;
  available: boolean;
}

export interface ListBigMacPricesRequest {
}

export interface ListBigMacPricesResponse {
  countries: BigMacCountryPrice[];
  fetchedAt: string;
  cheapestCountry: string;
  mostExpensiveCountry: string;
  wowAvgPct: number;
  wowAvailable: boolean;
  prevFetchedAt: string;
}

export interface BigMacCountryPrice {
  code: string;
  name: string;
  currency: string;
  flag: string;
  localPrice: number;
  usdPrice: number;
  fxRate: number;
  sourceSite: string;
  available: boolean;
  wowPct: number;
}

export interface GetNationalDebtRequest {
}

export interface GetNationalDebtResponse {
  entries: NationalDebtEntry[];
  seededAt: string;
  unavailable: boolean;
}

export interface NationalDebtEntry {
  iso3: string;
  debtUsd: number;
  gdpUsd: number;
  debtToGdp: number;
  annualGrowth: number;
  perSecondRate: number;
  perDayRate: number;
  baselineTs: string;
  source: string;
}

export interface ListFuelPricesRequest {
}

export interface ListFuelPricesResponse {
  countries: FuelCountryPrice[];
  fetchedAt: string;
  cheapestGasoline: string;
  cheapestDiesel: string;
  mostExpensiveGasoline: string;
  mostExpensiveDiesel: string;
  wowAvailable: boolean;
  prevFetchedAt: string;
  sourceCount: number;
  countryCount: number;
}

export interface FuelCountryPrice {
  code: string;
  name: string;
  currency: string;
  flag: string;
  gasoline?: FuelPrice;
  diesel?: FuelPrice;
  fxRate: number;
}

export interface FuelPrice {
  usdPrice: number;
  localPrice: number;
  grade: string;
  source: string;
  available: boolean;
  wowPct: number;
  observedAt: string;
}

export interface GetBlsSeriesRequest {
  seriesId: string;
  limit: number;
}

export interface GetBlsSeriesResponse {
  series?: BlsSeries;
}

export interface BlsSeries {
  seriesId: string;
  title: string;
  units: string;
  observations: BlsObservation[];
}

export interface BlsObservation {
  year: string;
  period: string;
  periodName: string;
  value: string;
}

export interface GetEconomicCalendarRequest {
  fromDate: string;
  toDate: string;
}

export interface GetEconomicCalendarResponse {
  events: EconomicEvent[];
  fromDate: string;
  toDate: string;
  total: number;
  unavailable: boolean;
}

export interface EconomicEvent {
  event: string;
  country: string;
  date: string;
  impact: string;
  actual: string;
  estimate: string;
  previous: string;
  unit: string;
}

export interface GetCrudeInventoriesRequest {
}

export interface GetCrudeInventoriesResponse {
  weeks: CrudeInventoryWeek[];
  latestPeriod: string;
}

export interface CrudeInventoryWeek {
  period: string;
  stocksMb: number;
  weeklyChangeMb?: number;
}

export interface GetNatGasStorageRequest {
}

export interface GetNatGasStorageResponse {
  weeks: NatGasStorageWeek[];
  latestPeriod: string;
}

export interface NatGasStorageWeek {
  period: string;
  storBcf: number;
  weeklyChangeBcf?: number;
}

export interface GetEcbFxRatesRequest {
}

export interface GetEcbFxRatesResponse {
  rates: EcbFxRate[];
  updatedAt: string;
  seededAt: string;
  unavailable: boolean;
}

export interface EcbFxRate {
  pair: string;
  rate: number;
  date: string;
  change1d: number;
}

export interface GetEurostatCountryDataRequest {
}

export interface GetEurostatCountryDataResponse {
  countries: Record<string, EurostatCountryEntry>;
  seededAt: string;
  unavailable: boolean;
}

export interface EurostatCountryEntry {
  cpi?: EurostatMetric;
  unemployment?: EurostatMetric;
  gdpGrowth?: EurostatMetric;
}

export interface EurostatMetric {
  value: number;
  date: string;
  unit: string;
  priorValue: number;
  hasPrior: boolean;
}

export interface GetEuGasStorageRequest {
}

export interface GetEuGasStorageResponse {
  fillPct: number;
  fillPctChange1d: number;
  gasDaysConsumption: number;
  trend: string;
  history: EuGasStorageHistoryEntry[];
  seededAt: string;
  updatedAt: string;
  unavailable: boolean;
}

export interface EuGasStorageHistoryEntry {
  date: string;
  fillPct: number;
  gasTwh: number;
}

export interface GetEuYieldCurveRequest {
}

export interface GetEuYieldCurveResponse {
  data?: EuYieldCurveData;
  unavailable: boolean;
}

export interface EuYieldCurveData {
  date: string;
  rates: Record<string, number>;
  source: string;
  updatedAt: string;
}

export interface GetEuFsiRequest {
}

export interface GetEuFsiResponse {
  latestValue: number;
  latestDate: string;
  label: string;
  history: EuFsiObservation[];
  seededAt: string;
  unavailable: boolean;
}

export interface EuFsiObservation {
  date: string;
  value: number;
}

export interface GetEconomicStressRequest {
}

export interface GetEconomicStressResponse {
  compositeScore: number;
  label: string;
  components: EconomicStressComponent[];
  seededAt: string;
  unavailable: boolean;
}

export interface EconomicStressComponent {
  id: string;
  label: string;
  rawValue: number;
  score: number;
  weight: number;
  missing: boolean;
}

export interface GetFaoFoodPriceIndexRequest {
}

export interface GetFaoFoodPriceIndexResponse {
  points: FaoFoodPricePoint[];
  fetchedAt: string;
  currentFfpi: number;
  momPct: number;
  yoyPct: number;
}

export interface FaoFoodPricePoint {
  date: string;
  ffpi: number;
  meat: number;
  dairy: number;
  cereals: number;
  oils: number;
  sugar: number;
}

export interface GetOilStocksAnalysisRequest {
}

export interface GetOilStocksAnalysisResponse {
  updatedAt: string;
  dataMonth: string;
  ieaMembers: OilStocksAnalysisMember[];
  belowObligation: string[];
  regionalSummary?: OilStocksRegionalSummary;
  unavailable: boolean;
}

export interface OilStocksAnalysisMember {
  iso2: string;
  daysOfCover?: number;
  netExporter: boolean;
  belowObligation: boolean;
  obligationMet: boolean;
  rank: number;
  vsObligation?: number;
}

export interface OilStocksRegionalSummary {
  europe?: OilStocksRegionalSummaryEurope;
  asiaPacific?: OilStocksRegionalSummaryAsiaPacific;
  northAmerica?: OilStocksRegionalSummaryNorthAmerica;
}

export interface OilStocksRegionalSummaryEurope {
  avgDays?: number;
  minDays?: number;
  countBelowObligation: number;
}

export interface OilStocksRegionalSummaryAsiaPacific {
  avgDays?: number;
  minDays?: number;
  countBelowObligation: number;
}

export interface OilStocksRegionalSummaryNorthAmerica {
  netExporters: number;
  avgDays?: number;
}

export interface GetOilInventoriesRequest {
}

export interface GetOilInventoriesResponse {
  crudeWeeks: CrudeInventoryWeekRef[];
  spr?: OilInventoriesSprSnapshot;
  natGasWeeks: NatGasWeekRef[];
  euGas?: OilInventoriesEuGas;
  ieaStocks?: OilInventoriesIeaStocks;
  refinery?: OilInventoriesRefinery;
  updatedAt: string;
}

export interface CrudeInventoryWeekRef {
  period: string;
  stocksMb: number;
  weeklyChangeMb?: number;
}

export interface OilInventoriesSprSnapshot {
  latestStocksMb: number;
  changeWow: number;
  weeks: OilInventoriesSprWeek[];
}

export interface OilInventoriesSprWeek {
  period: string;
  stocksMb: number;
}

export interface NatGasWeekRef {
  period: string;
  storBcf: number;
  weeklyChangeBcf?: number;
}

export interface OilInventoriesEuGas {
  fillPct: number;
  fillPctChange1d: number;
  trend: string;
  history: OilInventoriesEuGasDay[];
}

export interface OilInventoriesEuGasDay {
  date: string;
  fillPct: number;
}

export interface OilInventoriesIeaStocks {
  dataMonth: string;
  members: OilInventoriesIeaMember[];
  europe?: OilInventoriesRegionStats;
  asiaPacific?: OilInventoriesRegionStats;
  northAmerica?: OilInventoriesRegionStats;
}

export interface OilInventoriesIeaMember {
  iso2: string;
  daysOfCover?: number;
  netExporter: boolean;
  belowObligation: boolean;
}

export interface OilInventoriesRegionStats {
  avgDays?: number;
  minDays?: number;
  countBelowObligation?: number;
}

export interface OilInventoriesRefinery {
  inputsMbpd: number;
  period: string;
}

export interface GetEnergyCrisisPoliciesRequest {
  countryCode: string;
  category: string;
}

export interface GetEnergyCrisisPoliciesResponse {
  source: string;
  sourceUrl: string;
  context: string;
  policies: EnergyCrisisPolicy[];
  updatedAt: string;
  unavailable: boolean;
}

export interface EnergyCrisisPolicy {
  country: string;
  countryCode: string;
  category: string;
  sector: string;
  measure: string;
  dateAnnounced: string;
  status: string;
}

export interface FieldViolation {
  field: string;
  description: string;
}

export class ValidationError extends Error {
  violations: FieldViolation[];

  constructor(violations: FieldViolation[]) {
    super("Validation failed");
    this.name = "ValidationError";
    this.violations = violations;
  }
}

export class ApiError extends Error {
  statusCode: number;
  body: string;

  constructor(statusCode: number, message: string, body: string) {
    super(message);
    this.name = "ApiError";
    this.statusCode = statusCode;
    this.body = body;
  }
}

export interface ServerContext {
  request: Request;
  pathParams: Record<string, string>;
  headers: Record<string, string>;
}

export interface ServerOptions {
  onError?: (error: unknown, req: Request) => Response | Promise<Response>;
  validateRequest?: (methodName: string, body: unknown) => FieldViolation[] | undefined;
}

export interface RouteDescriptor {
  method: string;
  path: string;
  handler: (req: Request) => Promise<Response>;
}

export interface EconomicServiceHandler {
  getFredSeries(ctx: ServerContext, req: GetFredSeriesRequest): Promise<GetFredSeriesResponse>;
  listWorldBankIndicators(ctx: ServerContext, req: ListWorldBankIndicatorsRequest): Promise<ListWorldBankIndicatorsResponse>;
  getEnergyPrices(ctx: ServerContext, req: GetEnergyPricesRequest): Promise<GetEnergyPricesResponse>;
  getMacroSignals(ctx: ServerContext, req: GetMacroSignalsRequest): Promise<GetMacroSignalsResponse>;
  getEnergyCapacity(ctx: ServerContext, req: GetEnergyCapacityRequest): Promise<GetEnergyCapacityResponse>;
  getBisPolicyRates(ctx: ServerContext, req: GetBisPolicyRatesRequest): Promise<GetBisPolicyRatesResponse>;
  getBisExchangeRates(ctx: ServerContext, req: GetBisExchangeRatesRequest): Promise<GetBisExchangeRatesResponse>;
  getBisCredit(ctx: ServerContext, req: GetBisCreditRequest): Promise<GetBisCreditResponse>;
  getFredSeriesBatch(ctx: ServerContext, req: GetFredSeriesBatchRequest): Promise<GetFredSeriesBatchResponse>;
  listGroceryBasketPrices(ctx: ServerContext, req: ListGroceryBasketPricesRequest): Promise<ListGroceryBasketPricesResponse>;
  listBigMacPrices(ctx: ServerContext, req: ListBigMacPricesRequest): Promise<ListBigMacPricesResponse>;
  getNationalDebt(ctx: ServerContext, req: GetNationalDebtRequest): Promise<GetNationalDebtResponse>;
  listFuelPrices(ctx: ServerContext, req: ListFuelPricesRequest): Promise<ListFuelPricesResponse>;
  getBlsSeries(ctx: ServerContext, req: GetBlsSeriesRequest): Promise<GetBlsSeriesResponse>;
  getEconomicCalendar(ctx: ServerContext, req: GetEconomicCalendarRequest): Promise<GetEconomicCalendarResponse>;
  getCrudeInventories(ctx: ServerContext, req: GetCrudeInventoriesRequest): Promise<GetCrudeInventoriesResponse>;
  getNatGasStorage(ctx: ServerContext, req: GetNatGasStorageRequest): Promise<GetNatGasStorageResponse>;
  getEcbFxRates(ctx: ServerContext, req: GetEcbFxRatesRequest): Promise<GetEcbFxRatesResponse>;
  getEurostatCountryData(ctx: ServerContext, req: GetEurostatCountryDataRequest): Promise<GetEurostatCountryDataResponse>;
  getEuGasStorage(ctx: ServerContext, req: GetEuGasStorageRequest): Promise<GetEuGasStorageResponse>;
  getEuYieldCurve(ctx: ServerContext, req: GetEuYieldCurveRequest): Promise<GetEuYieldCurveResponse>;
  getEuFsi(ctx: ServerContext, req: GetEuFsiRequest): Promise<GetEuFsiResponse>;
  getEconomicStress(ctx: ServerContext, req: GetEconomicStressRequest): Promise<GetEconomicStressResponse>;
  getFaoFoodPriceIndex(ctx: ServerContext, req: GetFaoFoodPriceIndexRequest): Promise<GetFaoFoodPriceIndexResponse>;
  getOilStocksAnalysis(ctx: ServerContext, req: GetOilStocksAnalysisRequest): Promise<GetOilStocksAnalysisResponse>;
  getOilInventories(ctx: ServerContext, req: GetOilInventoriesRequest): Promise<GetOilInventoriesResponse>;
  getEnergyCrisisPolicies(ctx: ServerContext, req: GetEnergyCrisisPoliciesRequest): Promise<GetEnergyCrisisPoliciesResponse>;
}

export function createEconomicServiceRoutes(
  handler: EconomicServiceHandler,
  options?: ServerOptions,
): RouteDescriptor[] {
  return [
    {
      method: "GET",
      path: "/api/economic/v1/get-fred-series",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const url = new URL(req.url, "http://localhost");
          const params = url.searchParams;
          const body: GetFredSeriesRequest = {
            seriesId: params.get("series_id") ?? "",
            limit: Number(params.get("limit") ?? "0"),
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("getFredSeries", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getFredSeries(ctx, body);
          return new Response(JSON.stringify(result as GetFredSeriesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/list-world-bank-indicators",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const url = new URL(req.url, "http://localhost");
          const params = url.searchParams;
          const body: ListWorldBankIndicatorsRequest = {
            indicatorCode: params.get("indicator_code") ?? "",
            countryCode: params.get("country_code") ?? "",
            year: Number(params.get("year") ?? "0"),
            pageSize: Number(params.get("page_size") ?? "0"),
            cursor: params.get("cursor") ?? "",
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("listWorldBankIndicators", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.listWorldBankIndicators(ctx, body);
          return new Response(JSON.stringify(result as ListWorldBankIndicatorsResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-energy-prices",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const url = new URL(req.url, "http://localhost");
          const params = url.searchParams;
          const body: GetEnergyPricesRequest = {
            commodities: params.get("commodities") ?? "",
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("getEnergyPrices", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEnergyPrices(ctx, body);
          return new Response(JSON.stringify(result as GetEnergyPricesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-macro-signals",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetMacroSignalsRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getMacroSignals(ctx, body);
          return new Response(JSON.stringify(result as GetMacroSignalsResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-energy-capacity",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const url = new URL(req.url, "http://localhost");
          const params = url.searchParams;
          const body: GetEnergyCapacityRequest = {
            energySources: params.get("energy_sources") ?? "",
            years: Number(params.get("years") ?? "0"),
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("getEnergyCapacity", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEnergyCapacity(ctx, body);
          return new Response(JSON.stringify(result as GetEnergyCapacityResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-bis-policy-rates",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetBisPolicyRatesRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getBisPolicyRates(ctx, body);
          return new Response(JSON.stringify(result as GetBisPolicyRatesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-bis-exchange-rates",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetBisExchangeRatesRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getBisExchangeRates(ctx, body);
          return new Response(JSON.stringify(result as GetBisExchangeRatesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-bis-credit",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetBisCreditRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getBisCredit(ctx, body);
          return new Response(JSON.stringify(result as GetBisCreditResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "POST",
      path: "/api/economic/v1/get-fred-series-batch",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = await req.json() as GetFredSeriesBatchRequest;
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("getFredSeriesBatch", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getFredSeriesBatch(ctx, body);
          return new Response(JSON.stringify(result as GetFredSeriesBatchResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/list-grocery-basket-prices",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as ListGroceryBasketPricesRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.listGroceryBasketPrices(ctx, body);
          return new Response(JSON.stringify(result as ListGroceryBasketPricesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/list-bigmac-prices",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as ListBigMacPricesRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.listBigMacPrices(ctx, body);
          return new Response(JSON.stringify(result as ListBigMacPricesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-national-debt",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetNationalDebtRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getNationalDebt(ctx, body);
          return new Response(JSON.stringify(result as GetNationalDebtResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/list-fuel-prices",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as ListFuelPricesRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.listFuelPrices(ctx, body);
          return new Response(JSON.stringify(result as ListFuelPricesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-bls-series",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const url = new URL(req.url, "http://localhost");
          const params = url.searchParams;
          const body: GetBlsSeriesRequest = {
            seriesId: params.get("series_id") ?? "",
            limit: Number(params.get("limit") ?? "0"),
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("getBlsSeries", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getBlsSeries(ctx, body);
          return new Response(JSON.stringify(result as GetBlsSeriesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-economic-calendar",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const url = new URL(req.url, "http://localhost");
          const params = url.searchParams;
          const body: GetEconomicCalendarRequest = {
            fromDate: params.get("fromDate") ?? "",
            toDate: params.get("toDate") ?? "",
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("getEconomicCalendar", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEconomicCalendar(ctx, body);
          return new Response(JSON.stringify(result as GetEconomicCalendarResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-crude-inventories",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetCrudeInventoriesRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getCrudeInventories(ctx, body);
          return new Response(JSON.stringify(result as GetCrudeInventoriesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-nat-gas-storage",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetNatGasStorageRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getNatGasStorage(ctx, body);
          return new Response(JSON.stringify(result as GetNatGasStorageResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-ecb-fx-rates",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetEcbFxRatesRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEcbFxRates(ctx, body);
          return new Response(JSON.stringify(result as GetEcbFxRatesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-eurostat-country-data",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetEurostatCountryDataRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEurostatCountryData(ctx, body);
          return new Response(JSON.stringify(result as GetEurostatCountryDataResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-eu-gas-storage",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetEuGasStorageRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEuGasStorage(ctx, body);
          return new Response(JSON.stringify(result as GetEuGasStorageResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-eu-yield-curve",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetEuYieldCurveRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEuYieldCurve(ctx, body);
          return new Response(JSON.stringify(result as GetEuYieldCurveResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-eu-fsi",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetEuFsiRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEuFsi(ctx, body);
          return new Response(JSON.stringify(result as GetEuFsiResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-economic-stress",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetEconomicStressRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEconomicStress(ctx, body);
          return new Response(JSON.stringify(result as GetEconomicStressResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-fao-food-price-index",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetFaoFoodPriceIndexRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getFaoFoodPriceIndex(ctx, body);
          return new Response(JSON.stringify(result as GetFaoFoodPriceIndexResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-oil-stocks-analysis",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetOilStocksAnalysisRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getOilStocksAnalysis(ctx, body);
          return new Response(JSON.stringify(result as GetOilStocksAnalysisResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-oil-inventories",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetOilInventoriesRequest;

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getOilInventories(ctx, body);
          return new Response(JSON.stringify(result as GetOilInventoriesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
    {
      method: "GET",
      path: "/api/economic/v1/get-energy-crisis-policies",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const url = new URL(req.url, "http://localhost");
          const params = url.searchParams;
          const body: GetEnergyCrisisPoliciesRequest = {
            countryCode: params.get("country_code") ?? "",
            category: params.get("category") ?? "",
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("getEnergyCrisisPolicies", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

          const ctx: ServerContext = {
            request: req,
            pathParams,
            headers: Object.fromEntries(req.headers.entries()),
          };

          const result = await handler.getEnergyCrisisPolicies(ctx, body);
          return new Response(JSON.stringify(result as GetEnergyCrisisPoliciesResponse), {
            status: 200,
            headers: { "Content-Type": "application/json" },
          });
        } catch (err: unknown) {
          if (err instanceof ValidationError) {
            return new Response(JSON.stringify({ violations: err.violations }), {
              status: 400,
              headers: { "Content-Type": "application/json" },
            });
          }
          if (options?.onError) {
            return options.onError(err, req);
          }
          const message = err instanceof Error ? err.message : String(err);
          return new Response(JSON.stringify({ message }), {
            status: 500,
            headers: { "Content-Type": "application/json" },
          });
        }
      },
    },
  ];
}

