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

export interface ListInternetOutagesRequest {
  start: number;
  end: number;
  pageSize: number;
  cursor: string;
  country: string;
}

export interface ListInternetOutagesResponse {
  outages: InternetOutage[];
  pagination?: PaginationResponse;
}

export interface InternetOutage {
  id: string;
  title: string;
  link: string;
  description: string;
  detectedAt: number;
  country: string;
  region: string;
  location?: GeoCoordinates;
  severity: OutageSeverity;
  categories: string[];
  cause: string;
  outageType: string;
  endedAt: number;
}

export interface GeoCoordinates {
  latitude: number;
  longitude: number;
}

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

export interface ListServiceStatusesRequest {
  status: ServiceOperationalStatus;
}

export interface ListServiceStatusesResponse {
  statuses: ServiceStatus[];
}

export interface ServiceStatus {
  id: string;
  name: string;
  status: ServiceOperationalStatus;
  description: string;
  url: string;
  checkedAt: number;
  latencyMs: number;
}

export interface GetTemporalBaselineRequest {
  type: string;
  region: string;
  count: number;
}

export interface GetTemporalBaselineResponse {
  anomaly?: BaselineAnomaly;
  baseline?: BaselineStats;
  learning: boolean;
  sampleCount: number;
  samplesNeeded: number;
  error: string;
}

export interface BaselineAnomaly {
  zScore: number;
  severity: string;
  multiplier: number;
}

export interface BaselineStats {
  mean: number;
  stdDev: number;
  sampleCount: number;
}

export interface GetIpGeoRequest {
}

export interface GetIpGeoResponse {
  country: string;
  region: string;
  city: string;
}

export interface ReverseGeocodeRequest {
  lat: number;
  lon: number;
}

export interface ReverseGeocodeResponse {
  country: string;
  code: string;
  displayName: string;
  error: string;
}

export interface GetBootstrapDataRequest {
  tier: string;
  keys: string[];
}

export interface GetBootstrapDataResponse {
  data: Record<string, string>;
  missing: string[];
}

export interface RecordBaselineSnapshotRequest {
  updates: BaselineUpdate[];
}

export interface BaselineUpdate {
  type: string;
  region: string;
  count: number;
}

export interface RecordBaselineSnapshotResponse {
  updated: number;
  error: string;
}

export interface GetCableHealthRequest {
}

export interface GetCableHealthResponse {
  generatedAt: number;
  cables: Record<string, CableHealthRecord>;
}

export interface CableHealthRecord {
  status: CableHealthStatus;
  score: number;
  confidence: number;
  lastUpdated: number;
  evidence: CableHealthEvidence[];
}

export interface CableHealthEvidence {
  source: string;
  summary: string;
  ts: number;
}

export interface ListTemporalAnomaliesRequest {
}

export interface ListTemporalAnomaliesResponse {
  anomalies: TemporalAnomaly[];
  trackedTypes: string[];
  computedAt: string;
}

export interface TemporalAnomaly {
  type: string;
  region: string;
  currentCount: number;
  expectedCount: number;
  zScore: number;
  severity: string;
  multiplier: number;
  message: string;
}

export interface ListInternetDdosAttacksRequest {
}

export interface ListInternetDdosAttacksResponse {
  protocol: DdosAttackSummaryEntry[];
  vector: DdosAttackSummaryEntry[];
  dateRangeStart: string;
  dateRangeEnd: string;
  topTargetLocations: DdosLocationHit[];
}

export interface DdosAttackSummaryEntry {
  label: string;
  percentage: number;
}

export interface DdosLocationHit {
  countryCode: string;
  countryName: string;
  percentage: number;
  latitude: number;
  longitude: number;
}

export interface ListInternetTrafficAnomaliesRequest {
  country: string;
}

export interface ListInternetTrafficAnomaliesResponse {
  anomalies: TrafficAnomaly[];
  totalCount: number;
}

export interface TrafficAnomaly {
  uuid: string;
  type: string;
  status: string;
  startDate: number;
  endDate: number;
  asn: string;
  asnName: string;
  locationCode: string;
  locationName: string;
  latitude: number;
  longitude: number;
}

export type CableHealthStatus = "CABLE_HEALTH_STATUS_UNSPECIFIED" | "CABLE_HEALTH_STATUS_OK" | "CABLE_HEALTH_STATUS_DEGRADED" | "CABLE_HEALTH_STATUS_FAULT";

export type OutageSeverity = "OUTAGE_SEVERITY_UNSPECIFIED" | "OUTAGE_SEVERITY_PARTIAL" | "OUTAGE_SEVERITY_MAJOR" | "OUTAGE_SEVERITY_TOTAL";

export type ServiceOperationalStatus = "SERVICE_OPERATIONAL_STATUS_UNSPECIFIED" | "SERVICE_OPERATIONAL_STATUS_OPERATIONAL" | "SERVICE_OPERATIONAL_STATUS_DEGRADED" | "SERVICE_OPERATIONAL_STATUS_PARTIAL_OUTAGE" | "SERVICE_OPERATIONAL_STATUS_MAJOR_OUTAGE" | "SERVICE_OPERATIONAL_STATUS_MAINTENANCE";

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 InfrastructureServiceHandler {
  listInternetOutages(ctx: ServerContext, req: ListInternetOutagesRequest): Promise<ListInternetOutagesResponse>;
  listServiceStatuses(ctx: ServerContext, req: ListServiceStatusesRequest): Promise<ListServiceStatusesResponse>;
  getTemporalBaseline(ctx: ServerContext, req: GetTemporalBaselineRequest): Promise<GetTemporalBaselineResponse>;
  getIpGeo(ctx: ServerContext, req: GetIpGeoRequest): Promise<GetIpGeoResponse>;
  reverseGeocode(ctx: ServerContext, req: ReverseGeocodeRequest): Promise<ReverseGeocodeResponse>;
  getBootstrapData(ctx: ServerContext, req: GetBootstrapDataRequest): Promise<GetBootstrapDataResponse>;
  recordBaselineSnapshot(ctx: ServerContext, req: RecordBaselineSnapshotRequest): Promise<RecordBaselineSnapshotResponse>;
  getCableHealth(ctx: ServerContext, req: GetCableHealthRequest): Promise<GetCableHealthResponse>;
  listTemporalAnomalies(ctx: ServerContext, req: ListTemporalAnomaliesRequest): Promise<ListTemporalAnomaliesResponse>;
  listInternetDdosAttacks(ctx: ServerContext, req: ListInternetDdosAttacksRequest): Promise<ListInternetDdosAttacksResponse>;
  listInternetTrafficAnomalies(ctx: ServerContext, req: ListInternetTrafficAnomaliesRequest): Promise<ListInternetTrafficAnomaliesResponse>;
}

export function createInfrastructureServiceRoutes(
  handler: InfrastructureServiceHandler,
  options?: ServerOptions,
): RouteDescriptor[] {
  return [
    {
      method: "GET",
      path: "/api/infrastructure/v1/list-internet-outages",
      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: ListInternetOutagesRequest = {
            start: Number(params.get("start") ?? "0"),
            end: Number(params.get("end") ?? "0"),
            pageSize: Number(params.get("page_size") ?? "0"),
            cursor: params.get("cursor") ?? "",
            country: params.get("country") ?? "",
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("listInternetOutages", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

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

          const result = await handler.listInternetOutages(ctx, body);
          return new Response(JSON.stringify(result as ListInternetOutagesResponse), {
            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/infrastructure/v1/list-service-statuses",
      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: ListServiceStatusesRequest = {
            status: params.get("status") ?? "",
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("listServiceStatuses", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

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

          const result = await handler.listServiceStatuses(ctx, body);
          return new Response(JSON.stringify(result as ListServiceStatusesResponse), {
            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/infrastructure/v1/get-temporal-baseline",
      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: GetTemporalBaselineRequest = {
            type: params.get("type") ?? "",
            region: params.get("region") ?? "",
            count: Number(params.get("count") ?? "0"),
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("getTemporalBaseline", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

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

          const result = await handler.getTemporalBaseline(ctx, body);
          return new Response(JSON.stringify(result as GetTemporalBaselineResponse), {
            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/infrastructure/v1/get-ip-geo",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetIpGeoRequest;

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

          const result = await handler.getIpGeo(ctx, body);
          return new Response(JSON.stringify(result as GetIpGeoResponse), {
            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/infrastructure/v1/reverse-geocode",
      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: ReverseGeocodeRequest = {
            lat: Number(params.get("lat") ?? "0"),
            lon: Number(params.get("lon") ?? "0"),
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("reverseGeocode", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

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

          const result = await handler.reverseGeocode(ctx, body);
          return new Response(JSON.stringify(result as ReverseGeocodeResponse), {
            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/infrastructure/v1/get-bootstrap-data",
      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: GetBootstrapDataRequest = {
            tier: params.get("tier") ?? "",
            keys: params.get("keys") ?? "",
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("getBootstrapData", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

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

          const result = await handler.getBootstrapData(ctx, body);
          return new Response(JSON.stringify(result as GetBootstrapDataResponse), {
            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/infrastructure/v1/record-baseline-snapshot",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = await req.json() as RecordBaselineSnapshotRequest;
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("recordBaselineSnapshot", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

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

          const result = await handler.recordBaselineSnapshot(ctx, body);
          return new Response(JSON.stringify(result as RecordBaselineSnapshotResponse), {
            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/infrastructure/v1/get-cable-health",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as GetCableHealthRequest;

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

          const result = await handler.getCableHealth(ctx, body);
          return new Response(JSON.stringify(result as GetCableHealthResponse), {
            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/infrastructure/v1/list-temporal-anomalies",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as ListTemporalAnomaliesRequest;

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

          const result = await handler.listTemporalAnomalies(ctx, body);
          return new Response(JSON.stringify(result as ListTemporalAnomaliesResponse), {
            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/infrastructure/v1/list-internet-ddos-attacks",
      handler: async (req: Request): Promise<Response> => {
        try {
          const pathParams: Record<string, string> = {};
          const body = {} as ListInternetDdosAttacksRequest;

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

          const result = await handler.listInternetDdosAttacks(ctx, body);
          return new Response(JSON.stringify(result as ListInternetDdosAttacksResponse), {
            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/infrastructure/v1/list-internet-traffic-anomalies",
      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: ListInternetTrafficAnomaliesRequest = {
            country: params.get("country") ?? "",
          };
          if (options?.validateRequest) {
            const bodyViolations = options.validateRequest("listInternetTrafficAnomalies", body);
            if (bodyViolations) {
              throw new ValidationError(bodyViolations);
            }
          }

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

          const result = await handler.listInternetTrafficAnomalies(ctx, body);
          return new Response(JSON.stringify(result as ListInternetTrafficAnomaliesResponse), {
            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" },
          });
        }
      },
    },
  ];
}

