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

export interface GetRiskScoresRequest {
  region: string;
}

export interface GetRiskScoresResponse {
  ciiScores: CiiScore[];
  strategicRisks: StrategicRisk[];
}

export interface CiiScore {
  region: string;
  staticBaseline: number;
  dynamicScore: number;
  combinedScore: number;
  trend: TrendDirection;
  components?: CiiComponents;
  computedAt: number;
}

export interface CiiComponents {
  newsActivity: number;
  ciiContribution: number;
  geoConvergence: number;
  militaryActivity: number;
}

export interface StrategicRisk {
  region: string;
  level: SeverityLevel;
  score: number;
  factors: string[];
  trend: TrendDirection;
}

export interface GetPizzintStatusRequest {
  includeGdelt: boolean;
}

export interface GetPizzintStatusResponse {
  pizzint?: PizzintStatus;
  tensionPairs: GdeltTensionPair[];
}

export interface PizzintStatus {
  defconLevel: number;
  defconLabel: string;
  aggregateActivity: number;
  activeSpikes: number;
  locationsMonitored: number;
  locationsOpen: number;
  updatedAt: number;
  dataFreshness: DataFreshness;
  locations: PizzintLocation[];
}

export interface PizzintLocation {
  placeId: string;
  name: string;
  address: string;
  currentPopularity: number;
  percentageOfUsual: number;
  isSpike: boolean;
  spikeMagnitude: number;
  dataSource: string;
  recordedAt: string;
  dataFreshness: DataFreshness;
  isClosedNow: boolean;
  lat: number;
  lng: number;
}

export interface GdeltTensionPair {
  id: string;
  countries: string[];
  label: string;
  score: number;
  trend: TrendDirection;
  changePercent: number;
  region: string;
}

export interface ClassifyEventRequest {
  title: string;
  description: string;
  source: string;
  country: string;
}

export interface ClassifyEventResponse {
  classification?: EventClassification;
}

export interface EventClassification {
  category: string;
  subcategory: string;
  severity: SeverityLevel;
  confidence: number;
  analysis: string;
  entities: string[];
}

export interface GetCountryRiskRequest {
  countryCode: string;
}

export interface GetCountryRiskResponse {
  countryCode: string;
  countryName: string;
  cii?: CiiScore;
  advisoryLevel: string;
  sanctionsActive: boolean;
  sanctionsCount: number;
  fetchedAt: number;
  upstreamUnavailable: boolean;
}

export interface GetCountryIntelBriefRequest {
  countryCode: string;
  framework: string;
}

export interface GetCountryIntelBriefResponse {
  countryCode: string;
  countryName: string;
  brief: string;
  model: string;
  generatedAt: number;
}

export interface SearchGdeltDocumentsRequest {
  query: string;
  maxRecords: number;
  timespan: string;
  toneFilter: string;
  sort: string;
}

export interface SearchGdeltDocumentsResponse {
  articles: GdeltArticle[];
  query: string;
  error: string;
}

export interface GdeltArticle {
  title: string;
  url: string;
  source: string;
  date: string;
  image: string;
  language: string;
  tone: number;
}

export interface DeductSituationRequest {
  query: string;
  geoContext: string;
  framework: string;
}

export interface DeductSituationResponse {
  analysis: string;
  model: string;
  provider: string;
}

export interface ListSatellitesRequest {
  country: string;
}

export interface ListSatellitesResponse {
  satellites: Satellite[];
}

export interface Satellite {
  id: string;
  name: string;
  country: string;
  type: string;
  alt: number;
  velocity: number;
  inclination: number;
  line1: string;
  line2: string;
}

export interface ListGpsInterferenceRequest {
  region: string;
}

export interface ListGpsInterferenceResponse {
  hexes: GpsJamHex[];
  stats?: GpsJamStats;
  source: string;
  fetchedAt: number;
}

export interface GpsJamHex {
  h3: string;
  lat: number;
  lon: number;
  level: InterferenceLevel;
  npAvg: number;
  sampleCount: number;
  aircraftCount: number;
}

export interface GpsJamStats {
  totalHexes: number;
  highCount: number;
  mediumCount: number;
}

export interface ListOrefAlertsRequest {
  mode: Mode;
}

export interface ListOrefAlertsResponse {
  configured: boolean;
  alerts: OrefAlert[];
  history: OrefWave[];
  historyCount24h: number;
  totalHistoryCount: number;
  timestampMs: number;
  error: string;
}

export interface OrefAlert {
  id: string;
  cat: string;
  title: string;
  data: string[];
  desc: string;
  timestampMs: number;
}

export interface OrefWave {
  alerts: OrefAlert[];
  timestampMs: number;
}

export interface ListTelegramFeedRequest {
  limit: number;
  topic: string;
  channel: string;
}

export interface ListTelegramFeedResponse {
  enabled: boolean;
  messages: TelegramMessage[];
  count: number;
  error: string;
}

export interface TelegramMessage {
  id: string;
  channelId: string;
  channelName: string;
  text: string;
  timestampMs: number;
  mediaUrls: string[];
  sourceUrl: string;
  topic: string;
}

export interface GetCompanyEnrichmentRequest {
  domain: string;
  name: string;
}

export interface GetCompanyEnrichmentResponse {
  company?: EnrichedCompany;
  github?: EnrichedGithub;
  techStack: TechStackItem[];
  secFilings?: SecFilings;
  hackerNewsMentions: HNMention[];
  enrichedAtMs: number;
  sources: string[];
}

export interface EnrichedCompany {
  name: string;
  domain: string;
  description: string;
  location: string;
  website: string;
  founded: number;
}

export interface EnrichedGithub {
  publicRepos: number;
  followers: number;
  avatarUrl: string;
}

export interface TechStackItem {
  name: string;
  category: string;
  confidence: number;
}

export interface SecFilings {
  totalFilings: number;
  recentFilings: SecFiling[];
}

export interface SecFiling {
  form: string;
  fileDate: string;
  description: string;
}

export interface HNMention {
  title: string;
  url: string;
  points: number;
  comments: number;
  createdAtMs: number;
}

export interface ListCompanySignalsRequest {
  company: string;
  domain: string;
}

export interface ListCompanySignalsResponse {
  company: string;
  domain: string;
  signals: CompanySignal[];
  summary?: SignalSummary;
  discoveredAtMs: number;
}

export interface CompanySignal {
  type: string;
  title: string;
  url: string;
  source: string;
  sourceTier: number;
  timestampMs: number;
  strength: string;
  engagement?: SignalEngagement;
}

export interface SignalEngagement {
  points: number;
  comments: number;
  stars: number;
  forks: number;
  mentions: number;
}

export interface SignalSummary {
  totalSignals: number;
  byType: Record<string, number>;
  strongestSignal?: CompanySignal;
  signalDiversity: number;
}

export interface GetCountryFactsRequest {
  countryCode: string;
}

export interface GetCountryFactsResponse {
  headOfState: string;
  headOfStateTitle: string;
  wikipediaSummary: string;
  wikipediaThumbnailUrl: string;
  population: number;
  capital: string;
  languages: string[];
  currencies: string[];
  areaSqKm: number;
  countryName: string;
}

export interface ListSecurityAdvisoriesRequest {
}

export interface ListSecurityAdvisoriesResponse {
  advisories: SecurityAdvisoryItem[];
  byCountry: Record<string, string>;
}

export interface SecurityAdvisoryItem {
  title: string;
  link: string;
  pubDate: string;
  source: string;
  sourceCountry: string;
  level: string;
  country: string;
}

export interface GetGdeltTopicTimelineRequest {
  topic: string;
}

export interface GetGdeltTopicTimelineResponse {
  topic: string;
  tone: GdeltTimelinePoint[];
  vol: GdeltTimelinePoint[];
  fetchedAt: string;
  error: string;
}

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

export interface ListCrossSourceSignalsRequest {
}

export interface ListCrossSourceSignalsResponse {
  signals: CrossSourceSignal[];
  evaluatedAt: number;
  compositeCount: number;
}

export interface CrossSourceSignal {
  id: string;
  type: CrossSourceSignalType;
  theater: string;
  summary: string;
  severity: CrossSourceSignalSeverity;
  severityScore: number;
  detectedAt: number;
  contributingTypes: string[];
  signalCount: number;
}

export interface ListMarketImplicationsRequest {
  frameworkId: string;
}

export interface ListMarketImplicationsResponse {
  cards: MarketImplicationCard[];
  degraded: boolean;
  emptyReason: string;
  generatedAt: string;
}

export interface MarketImplicationCard {
  ticker: string;
  name: string;
  direction: string;
  timeframe: string;
  confidence: string;
  title: string;
  narrative: string;
  riskCaveat: string;
  driver: string;
  transmissionChain: TransmissionNode[];
}

export interface TransmissionNode {
  node: string;
  impactType: string;
  logic: string;
}

export interface GetSocialVelocityRequest {
}

export interface GetSocialVelocityResponse {
  posts: SocialVelocityPost[];
  fetchedAt: number;
}

export interface SocialVelocityPost {
  id: string;
  title: string;
  subreddit: string;
  url: string;
  score: number;
  upvoteRatio: number;
  numComments: number;
  velocityScore: number;
  createdAt: number;
}

export interface GetCountryEnergyProfileRequest {
  countryCode: string;
}

export interface GetCountryEnergyProfileResponse {
  mixAvailable: boolean;
  mixYear: number;
  coalShare: number;
  gasShare: number;
  oilShare: number;
  nuclearShare: number;
  renewShare: number;
  windShare: number;
  solarShare: number;
  hydroShare: number;
  importShare: number;
  gasStorageAvailable: boolean;
  gasStorageFillPct: number;
  gasStorageChange1d: number;
  gasStorageTrend: string;
  gasStorageDate: string;
  electricityAvailable: boolean;
  electricityPriceMwh: number;
  electricitySource: string;
  electricityDate: string;
  jodiOilAvailable: boolean;
  jodiOilDataMonth: string;
  gasolineDemandKbd: number;
  gasolineImportsKbd: number;
  dieselDemandKbd: number;
  dieselImportsKbd: number;
  jetDemandKbd: number;
  jetImportsKbd: number;
  lpgDemandKbd: number;
  crudeImportsKbd: number;
  lpgImportsKbd: number;
  jodiGasAvailable: boolean;
  jodiGasDataMonth: string;
  gasTotalDemandTj: number;
  gasLngImportsTj: number;
  gasPipeImportsTj: number;
  gasLngShare: number;
  ieaStocksAvailable: boolean;
  ieaStocksDataMonth: string;
  ieaDaysOfCover: number;
  ieaNetExporter: boolean;
  ieaBelowObligation: boolean;
  emberFossilShare: number;
  emberRenewShare: number;
  emberNuclearShare: number;
  emberCoalShare: number;
  emberGasShare: number;
  emberDemandTwh: number;
  emberDataMonth: string;
  emberAvailable: boolean;
  sprRegime: string;
  sprCapacityMb: number;
  sprOperator: string;
  sprIeaMember: boolean;
  sprStockholdingModel: string;
  sprNote: string;
  sprSource: string;
  sprAsOf: string;
  sprAvailable: boolean;
}

export interface ComputeEnergyShockScenarioRequest {
  countryCode: string;
  chokepointId: string;
  disruptionPct: number;
  fuelMode: string;
}

export interface ComputeEnergyShockScenarioResponse {
  countryCode: string;
  chokepointId: string;
  disruptionPct: number;
  gulfCrudeShare: number;
  crudeLossKbd: number;
  products: ProductImpact[];
  effectiveCoverDays: number;
  assessment: string;
  dataAvailable: boolean;
  jodiOilCoverage: boolean;
  comtradeCoverage: boolean;
  ieaStocksCoverage: boolean;
  portwatchCoverage: boolean;
  coverageLevel: string;
  limitations: string[];
  degraded: boolean;
  chokepointConfidence: string;
  liveFlowRatio?: number;
  gasImpact?: GasImpact;
}

export interface ProductImpact {
  product: string;
  outputLossKbd: number;
  demandKbd: number;
  deficitPct: number;
}

export interface GasImpact {
  lngShareOfImports: number;
  lngImportsTj: number;
  lngDisruptionTj: number;
  totalDemandTj: number;
  deficitPct: number;
  dataAvailable: boolean;
  assessment: string;
  storage?: GasStorageBuffer;
  dataSource: string;
}

export interface GasStorageBuffer {
  fillPct: number;
  gasTwh: number;
  bufferDays: number;
  trend: string;
  date: string;
  scope: string;
}

export interface GetCountryPortActivityRequest {
  countryCode: string;
}

export interface CountryPortActivityResponse {
  ports: PortActivityEntry[];
  fetchedAt: string;
  available: boolean;
}

export interface PortActivityEntry {
  portId: string;
  portName: string;
  lat: number;
  lon: number;
  tankerCalls30d: number;
  trendDeltaPct: number;
  importTankerDwt: number;
  exportTankerDwt: number;
  anomalySignal: boolean;
}

export interface GetRegionalSnapshotRequest {
  regionId: string;
}

export interface GetRegionalSnapshotResponse {
  snapshot?: RegionalSnapshot;
}

export interface RegionalSnapshot {
  regionId: string;
  generatedAt: number;
  meta?: SnapshotMeta;
  regime?: RegimeState;
  balance?: BalanceVector;
  actors: ActorState[];
  leverageEdges: LeverageEdge[];
  scenarioSets: ScenarioSet[];
  transmissionPaths: TransmissionPath[];
  triggers?: TriggerLadder;
  mobility?: MobilityState;
  evidence: EvidenceItem[];
  narrative?: RegionalNarrative;
}

export interface SnapshotMeta {
  snapshotId: string;
  modelVersion: string;
  scoringVersion: string;
  geographyVersion: string;
  snapshotConfidence: number;
  missingInputs: string[];
  staleInputs: string[];
  validUntil: number;
  triggerReason: string;
  narrativeProvider: string;
  narrativeModel: string;
}

export interface RegimeState {
  label: string;
  previousLabel: string;
  transitionedAt: number;
  transitionDriver: string;
}

export interface BalanceVector {
  coercivePressure: number;
  domesticFragility: number;
  capitalStress: number;
  energyVulnerability: number;
  allianceCohesion: number;
  maritimeAccess: number;
  energyLeverage: number;
  netBalance: number;
  pressures: BalanceDriver[];
  buffers: BalanceDriver[];
}

export interface BalanceDriver {
  axis: string;
  description: string;
  magnitude: number;
  evidenceIds: string[];
  orientation: string;
}

export interface ActorState {
  actorId: string;
  name: string;
  role: string;
  leverageDomains: string[];
  leverageScore: number;
  delta: number;
  evidenceIds: string[];
}

export interface LeverageEdge {
  fromActorId: string;
  toActorId: string;
  mechanism: string;
  strength: number;
  evidenceIds: string[];
}

export interface ScenarioSet {
  horizon: string;
  lanes: ScenarioLane[];
}

export interface ScenarioLane {
  name: string;
  probability: number;
  triggerIds: string[];
  consequences: string[];
  transmissions: TransmissionPath[];
}

export interface TransmissionPath {
  start: string;
  mechanism: string;
  end: string;
  severity: string;
  corridorId: string;
  confidence: number;
  latencyHours: number;
  impactedAssetClass: string;
  impactedRegions: string[];
  magnitudeLow: number;
  magnitudeHigh: number;
  magnitudeUnit: string;
  templateId: string;
  templateVersion: string;
}

export interface TriggerLadder {
  active: Trigger[];
  watching: Trigger[];
  dormant: Trigger[];
}

export interface Trigger {
  id: string;
  description: string;
  threshold?: TriggerThreshold;
  activated: boolean;
  activatedAt: number;
  scenarioLane: string;
  evidenceIds: string[];
}

export interface TriggerThreshold {
  metric: string;
  operator: string;
  value: number;
  windowMinutes: number;
  baseline: string;
}

export interface MobilityState {
  airspace: AirspaceStatus[];
  flightCorridors: FlightCorridorStress[];
  airports: AirportNodeStatus[];
  rerouteIntensity: number;
  notamClosures: string[];
}

export interface AirspaceStatus {
  airspaceId: string;
  status: string;
  reason: string;
}

export interface FlightCorridorStress {
  corridor: string;
  stressLevel: number;
  reroutedFlights24h: number;
}

export interface AirportNodeStatus {
  icao: string;
  name: string;
  status: string;
  disruptionReason: string;
}

export interface EvidenceItem {
  id: string;
  type: string;
  source: string;
  summary: string;
  confidence: number;
  observedAt: number;
  theater: string;
  corridor: string;
}

export interface RegionalNarrative {
  situation?: NarrativeSection;
  balanceAssessment?: NarrativeSection;
  outlook24h?: NarrativeSection;
  outlook7d?: NarrativeSection;
  outlook30d?: NarrativeSection;
  watchItems: NarrativeSection[];
}

export interface NarrativeSection {
  text: string;
  evidenceIds: string[];
}

export interface GetRegimeHistoryRequest {
  regionId: string;
  limit: number;
}

export interface GetRegimeHistoryResponse {
  transitions: RegimeTransition[];
}

export interface RegimeTransition {
  regionId: string;
  label: string;
  previousLabel: string;
  transitionedAt: number;
  transitionDriver: string;
  snapshotId: string;
}

export interface GetRegionalBriefRequest {
  regionId: string;
}

export interface GetRegionalBriefResponse {
  brief?: RegionalBrief;
}

export interface RegionalBrief {
  regionId: string;
  generatedAt: number;
  periodStart: number;
  periodEnd: number;
  situationRecap: string;
  regimeTrajectory: string;
  keyDevelopments: string[];
  riskOutlook: string;
  provider: string;
  model: string;
}

export type SeverityLevel = "SEVERITY_LEVEL_UNSPECIFIED" | "SEVERITY_LEVEL_LOW" | "SEVERITY_LEVEL_MEDIUM" | "SEVERITY_LEVEL_HIGH";

export type TrendDirection = "TREND_DIRECTION_UNSPECIFIED" | "TREND_DIRECTION_RISING" | "TREND_DIRECTION_STABLE" | "TREND_DIRECTION_FALLING";

export type CrossSourceSignalSeverity = "CROSS_SOURCE_SIGNAL_SEVERITY_UNSPECIFIED" | "CROSS_SOURCE_SIGNAL_SEVERITY_LOW" | "CROSS_SOURCE_SIGNAL_SEVERITY_MEDIUM" | "CROSS_SOURCE_SIGNAL_SEVERITY_HIGH" | "CROSS_SOURCE_SIGNAL_SEVERITY_CRITICAL";

export type CrossSourceSignalType = "CROSS_SOURCE_SIGNAL_TYPE_UNSPECIFIED" | "CROSS_SOURCE_SIGNAL_TYPE_COMPOSITE_ESCALATION" | "CROSS_SOURCE_SIGNAL_TYPE_THERMAL_SPIKE" | "CROSS_SOURCE_SIGNAL_TYPE_GPS_JAMMING" | "CROSS_SOURCE_SIGNAL_TYPE_MILITARY_FLIGHT_SURGE" | "CROSS_SOURCE_SIGNAL_TYPE_UNREST_SURGE" | "CROSS_SOURCE_SIGNAL_TYPE_OREF_ALERT_CLUSTER" | "CROSS_SOURCE_SIGNAL_TYPE_VIX_SPIKE" | "CROSS_SOURCE_SIGNAL_TYPE_COMMODITY_SHOCK" | "CROSS_SOURCE_SIGNAL_TYPE_CYBER_ESCALATION" | "CROSS_SOURCE_SIGNAL_TYPE_SHIPPING_DISRUPTION" | "CROSS_SOURCE_SIGNAL_TYPE_SANCTIONS_SURGE" | "CROSS_SOURCE_SIGNAL_TYPE_EARTHQUAKE_SIGNIFICANT" | "CROSS_SOURCE_SIGNAL_TYPE_RADIATION_ANOMALY" | "CROSS_SOURCE_SIGNAL_TYPE_INFRASTRUCTURE_OUTAGE" | "CROSS_SOURCE_SIGNAL_TYPE_WILDFIRE_ESCALATION" | "CROSS_SOURCE_SIGNAL_TYPE_DISPLACEMENT_SURGE" | "CROSS_SOURCE_SIGNAL_TYPE_FORECAST_DETERIORATION" | "CROSS_SOURCE_SIGNAL_TYPE_MARKET_STRESS" | "CROSS_SOURCE_SIGNAL_TYPE_WEATHER_EXTREME" | "CROSS_SOURCE_SIGNAL_TYPE_MEDIA_TONE_DETERIORATION" | "CROSS_SOURCE_SIGNAL_TYPE_RISK_SCORE_SPIKE";

export type DataFreshness = "DATA_FRESHNESS_UNSPECIFIED" | "DATA_FRESHNESS_FRESH" | "DATA_FRESHNESS_STALE";

export type InterferenceLevel = "INTERFERENCE_LEVEL_UNSPECIFIED" | "INTERFERENCE_LEVEL_LOW" | "INTERFERENCE_LEVEL_MEDIUM" | "INTERFERENCE_LEVEL_HIGH";

export type Mode = "MODE_UNSPECIFIED" | "MODE_HISTORY";

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 IntelligenceServiceClientOptions {
  fetch?: typeof fetch;
  defaultHeaders?: Record<string, string>;
}

export interface IntelligenceServiceCallOptions {
  headers?: Record<string, string>;
  signal?: AbortSignal;
}

export class IntelligenceServiceClient {
  private baseURL: string;
  private fetchFn: typeof fetch;
  private defaultHeaders: Record<string, string>;

  constructor(baseURL: string, options?: IntelligenceServiceClientOptions) {
    this.baseURL = baseURL.replace(/\/+$/, "");
    this.fetchFn = options?.fetch ?? globalThis.fetch;
    this.defaultHeaders = { ...options?.defaultHeaders };
  }

  async getRiskScores(req: GetRiskScoresRequest, options?: IntelligenceServiceCallOptions): Promise<GetRiskScoresResponse> {
    let path = "/api/intelligence/v1/get-risk-scores";
    const params = new URLSearchParams();
    if (req.region != null && req.region !== "") params.set("region", String(req.region));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetRiskScoresResponse;
  }

  async getPizzintStatus(req: GetPizzintStatusRequest, options?: IntelligenceServiceCallOptions): Promise<GetPizzintStatusResponse> {
    let path = "/api/intelligence/v1/get-pizzint-status";
    const params = new URLSearchParams();
    if (req.includeGdelt) params.set("include_gdelt", String(req.includeGdelt));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetPizzintStatusResponse;
  }

  async classifyEvent(req: ClassifyEventRequest, options?: IntelligenceServiceCallOptions): Promise<ClassifyEventResponse> {
    let path = "/api/intelligence/v1/classify-event";
    const params = new URLSearchParams();
    if (req.title != null && req.title !== "") params.set("title", String(req.title));
    if (req.description != null && req.description !== "") params.set("description", String(req.description));
    if (req.source != null && req.source !== "") params.set("source", String(req.source));
    if (req.country != null && req.country !== "") params.set("country", String(req.country));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ClassifyEventResponse;
  }

  async getCountryRisk(req: GetCountryRiskRequest, options?: IntelligenceServiceCallOptions): Promise<GetCountryRiskResponse> {
    let path = "/api/intelligence/v1/get-country-risk";
    const params = new URLSearchParams();
    if (req.countryCode != null && req.countryCode !== "") params.set("country_code", String(req.countryCode));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetCountryRiskResponse;
  }

  async getCountryIntelBrief(req: GetCountryIntelBriefRequest, options?: IntelligenceServiceCallOptions): Promise<GetCountryIntelBriefResponse> {
    let path = "/api/intelligence/v1/get-country-intel-brief";
    const params = new URLSearchParams();
    if (req.countryCode != null && req.countryCode !== "") params.set("country_code", String(req.countryCode));
    if (req.framework != null && req.framework !== "") params.set("framework", String(req.framework));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetCountryIntelBriefResponse;
  }

  async searchGdeltDocuments(req: SearchGdeltDocumentsRequest, options?: IntelligenceServiceCallOptions): Promise<SearchGdeltDocumentsResponse> {
    let path = "/api/intelligence/v1/search-gdelt-documents";
    const params = new URLSearchParams();
    if (req.query != null && req.query !== "") params.set("query", String(req.query));
    if (req.maxRecords != null && req.maxRecords !== 0) params.set("max_records", String(req.maxRecords));
    if (req.timespan != null && req.timespan !== "") params.set("timespan", String(req.timespan));
    if (req.toneFilter != null && req.toneFilter !== "") params.set("tone_filter", String(req.toneFilter));
    if (req.sort != null && req.sort !== "") params.set("sort", String(req.sort));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as SearchGdeltDocumentsResponse;
  }

  async deductSituation(req: DeductSituationRequest, options?: IntelligenceServiceCallOptions): Promise<DeductSituationResponse> {
    let path = "/api/intelligence/v1/deduct-situation";
    const url = this.baseURL + path;

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "POST",
      headers,
      body: JSON.stringify(req),
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as DeductSituationResponse;
  }

  async listSatellites(req: ListSatellitesRequest, options?: IntelligenceServiceCallOptions): Promise<ListSatellitesResponse> {
    let path = "/api/intelligence/v1/list-satellites";
    const params = new URLSearchParams();
    if (req.country != null && req.country !== "") params.set("country", String(req.country));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ListSatellitesResponse;
  }

  async listGpsInterference(req: ListGpsInterferenceRequest, options?: IntelligenceServiceCallOptions): Promise<ListGpsInterferenceResponse> {
    let path = "/api/intelligence/v1/list-gps-interference";
    const params = new URLSearchParams();
    if (req.region != null && req.region !== "") params.set("region", String(req.region));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ListGpsInterferenceResponse;
  }

  async listOrefAlerts(req: ListOrefAlertsRequest, options?: IntelligenceServiceCallOptions): Promise<ListOrefAlertsResponse> {
    let path = "/api/intelligence/v1/list-oref-alerts";
    const params = new URLSearchParams();
    if (req.mode != null && req.mode !== "") params.set("mode", String(req.mode));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ListOrefAlertsResponse;
  }

  async listTelegramFeed(req: ListTelegramFeedRequest, options?: IntelligenceServiceCallOptions): Promise<ListTelegramFeedResponse> {
    let path = "/api/intelligence/v1/list-telegram-feed";
    const params = new URLSearchParams();
    if (req.limit != null && req.limit !== 0) params.set("limit", String(req.limit));
    if (req.topic != null && req.topic !== "") params.set("topic", String(req.topic));
    if (req.channel != null && req.channel !== "") params.set("channel", String(req.channel));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ListTelegramFeedResponse;
  }

  async getCompanyEnrichment(req: GetCompanyEnrichmentRequest, options?: IntelligenceServiceCallOptions): Promise<GetCompanyEnrichmentResponse> {
    let path = "/api/intelligence/v1/get-company-enrichment";
    const params = new URLSearchParams();
    if (req.domain != null && req.domain !== "") params.set("domain", String(req.domain));
    if (req.name != null && req.name !== "") params.set("name", String(req.name));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetCompanyEnrichmentResponse;
  }

  async listCompanySignals(req: ListCompanySignalsRequest, options?: IntelligenceServiceCallOptions): Promise<ListCompanySignalsResponse> {
    let path = "/api/intelligence/v1/list-company-signals";
    const params = new URLSearchParams();
    if (req.company != null && req.company !== "") params.set("company", String(req.company));
    if (req.domain != null && req.domain !== "") params.set("domain", String(req.domain));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ListCompanySignalsResponse;
  }

  async getCountryFacts(req: GetCountryFactsRequest, options?: IntelligenceServiceCallOptions): Promise<GetCountryFactsResponse> {
    let path = "/api/intelligence/v1/get-country-facts";
    const params = new URLSearchParams();
    if (req.countryCode != null && req.countryCode !== "") params.set("country_code", String(req.countryCode));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetCountryFactsResponse;
  }

  async listSecurityAdvisories(req: ListSecurityAdvisoriesRequest, options?: IntelligenceServiceCallOptions): Promise<ListSecurityAdvisoriesResponse> {
    let path = "/api/intelligence/v1/list-security-advisories";
    const url = this.baseURL + path;

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ListSecurityAdvisoriesResponse;
  }

  async getGdeltTopicTimeline(req: GetGdeltTopicTimelineRequest, options?: IntelligenceServiceCallOptions): Promise<GetGdeltTopicTimelineResponse> {
    let path = "/api/intelligence/v1/get-gdelt-topic-timeline";
    const params = new URLSearchParams();
    if (req.topic != null && req.topic !== "") params.set("topic", String(req.topic));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetGdeltTopicTimelineResponse;
  }

  async listCrossSourceSignals(req: ListCrossSourceSignalsRequest, options?: IntelligenceServiceCallOptions): Promise<ListCrossSourceSignalsResponse> {
    let path = "/api/intelligence/v1/list-cross-source-signals";
    const url = this.baseURL + path;

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ListCrossSourceSignalsResponse;
  }

  async listMarketImplications(req: ListMarketImplicationsRequest, options?: IntelligenceServiceCallOptions): Promise<ListMarketImplicationsResponse> {
    let path = "/api/intelligence/v1/list-market-implications";
    const params = new URLSearchParams();
    if (req.frameworkId != null && req.frameworkId !== "") params.set("frameworkId", String(req.frameworkId));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ListMarketImplicationsResponse;
  }

  async getSocialVelocity(req: GetSocialVelocityRequest, options?: IntelligenceServiceCallOptions): Promise<GetSocialVelocityResponse> {
    let path = "/api/intelligence/v1/get-social-velocity";
    const url = this.baseURL + path;

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetSocialVelocityResponse;
  }

  async getCountryEnergyProfile(req: GetCountryEnergyProfileRequest, options?: IntelligenceServiceCallOptions): Promise<GetCountryEnergyProfileResponse> {
    let path = "/api/intelligence/v1/get-country-energy-profile";
    const params = new URLSearchParams();
    if (req.countryCode != null && req.countryCode !== "") params.set("country_code", String(req.countryCode));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetCountryEnergyProfileResponse;
  }

  async computeEnergyShockScenario(req: ComputeEnergyShockScenarioRequest, options?: IntelligenceServiceCallOptions): Promise<ComputeEnergyShockScenarioResponse> {
    let path = "/api/intelligence/v1/compute-energy-shock";
    const params = new URLSearchParams();
    if (req.countryCode != null && req.countryCode !== "") params.set("country_code", String(req.countryCode));
    if (req.chokepointId != null && req.chokepointId !== "") params.set("chokepoint_id", String(req.chokepointId));
    if (req.disruptionPct != null && req.disruptionPct !== 0) params.set("disruption_pct", String(req.disruptionPct));
    if (req.fuelMode != null && req.fuelMode !== "") params.set("fuel_mode", String(req.fuelMode));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as ComputeEnergyShockScenarioResponse;
  }

  async getCountryPortActivity(req: GetCountryPortActivityRequest, options?: IntelligenceServiceCallOptions): Promise<CountryPortActivityResponse> {
    let path = "/api/intelligence/v1/get-country-port-activity";
    const params = new URLSearchParams();
    if (req.countryCode != null && req.countryCode !== "") params.set("country_code", String(req.countryCode));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as CountryPortActivityResponse;
  }

  async getRegionalSnapshot(req: GetRegionalSnapshotRequest, options?: IntelligenceServiceCallOptions): Promise<GetRegionalSnapshotResponse> {
    let path = "/api/intelligence/v1/get-regional-snapshot";
    const params = new URLSearchParams();
    if (req.regionId != null && req.regionId !== "") params.set("region_id", String(req.regionId));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetRegionalSnapshotResponse;
  }

  async getRegimeHistory(req: GetRegimeHistoryRequest, options?: IntelligenceServiceCallOptions): Promise<GetRegimeHistoryResponse> {
    let path = "/api/intelligence/v1/get-regime-history";
    const params = new URLSearchParams();
    if (req.regionId != null && req.regionId !== "") params.set("region_id", String(req.regionId));
    if (req.limit != null && req.limit !== 0) params.set("limit", String(req.limit));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetRegimeHistoryResponse;
  }

  async getRegionalBrief(req: GetRegionalBriefRequest, options?: IntelligenceServiceCallOptions): Promise<GetRegionalBriefResponse> {
    let path = "/api/intelligence/v1/get-regional-brief";
    const params = new URLSearchParams();
    if (req.regionId != null && req.regionId !== "") params.set("region_id", String(req.regionId));
    const url = this.baseURL + path + (params.toString() ? "?" + params.toString() : "");

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      ...this.defaultHeaders,
      ...options?.headers,
    };

    const resp = await this.fetchFn(url, {
      method: "GET",
      headers,
      signal: options?.signal,
    });

    if (!resp.ok) {
      return this.handleError(resp);
    }

    return await resp.json() as GetRegionalBriefResponse;
  }

  private async handleError(resp: Response): Promise<never> {
    const body = await resp.text();
    if (resp.status === 400) {
      try {
        const parsed = JSON.parse(body);
        if (parsed.violations) {
          throw new ValidationError(parsed.violations);
        }
      } catch (e) {
        if (e instanceof ValidationError) throw e;
      }
    }
    throw new ApiError(resp.status, `Request failed with status ${resp.status}`, body);
  }
}

