/**
 * GENERATED by `imprint emit` — DO NOT EDIT BY HAND.
 *
 * Tool: lookup_airport
 * Site: google-flights
 * Intent: Resolve a city or airport query into airport codes and structured airport details.
 *
 * To regenerate: imprint emit ~/.imprint/google-flights/lookup_airport/workflow.json --force
 */

import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import {
  executeWorkflow,
  type CredentialStore,
} from 'imprint/runtime';
import type { ToolResult, Workflow } from 'imprint/types';

const WORKFLOW: Workflow = {
  "toolName": "lookup_airport",
  "intent": {
    "description": "Resolve a city or airport query into airport codes and structured airport details.",
    "userSaid": "multi city from SJC to SAN to LAX to SFO"
  },
  "parameters": [
    {
      "name": "query",
      "type": "string",
      "description": "City or airport search text, e.g. 'san jose' or 'SJC'",
      "verified": true
    }
  ],
  "requests": [
    {
      "method": "POST",
      "url": "https://www.google.com/_/FlightsFrontendUi/data/batchexecute?rpcids=tDoGIe&source-path=%2Ftravel%2Fflights&f.sid=${state.f_sid}&bl=${state.bl}&hl=en-US&soc-app=162&soc-platform=1&soc-device=1&_reqid=608023&rt=c",
      "headers": {
        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "X-Same-Domain": "1",
        "Referer": "https://www.google.com/travel/flights",
        "Accept-Language": "en-US,en;q=0.9",
        "x-goog-ext-259736195-jspb": "[\"en-US\",\"US\",\"USD\",2,null,[420],null,null,7,[]]"
      },
      "body": "f.req=%5B%5B%5B%22tDoGIe%22%2C%22%5Bnull%2C%5B%5B%5C%22${param.query}%5C%22%2C0%5D%5D%5D%22%2Cnull%2C%22generic%22%5D%5D%5D&",
      "effect": "safe"
    }
  ],
  "site": "google-flights",
  "bootstrap": {
    "url": "https://www.google.com/travel/flights",
    "waitUntil": "domcontentloaded",
    "timeoutMs": 30000,
    "captures": [
      {
        "name": "f_sid",
        "required": true,
        "capability": "browser_bootstrap",
        "source": "html_regex",
        "pattern": "\"FdrFJe\":\"([^\"]+)\"",
        "group": 1
      },
      {
        "name": "bl",
        "required": true,
        "capability": "browser_bootstrap",
        "source": "html_regex",
        "pattern": "\"cfb2h\":\"([^\"]+)\"",
        "group": 1
      }
    ]
  },
  "parserModule": "./parser.ts",
  "requestTransformModule": "./request-transform.ts",
  "liveVerified": true
};

export interface LookupAirportInput {
  /** City or airport search text, e.g. 'san jose' or 'SJC' */
  query: string;
}

export async function lookupAirport(
  input: LookupAirportInput,
  opts: { credentials?: CredentialStore; fetchImpl?: typeof fetch; initialState?: Record<string, unknown> } = {},
): Promise<ToolResult> {
  const __dirname = dirname(fileURLToPath(import.meta.url));
  const params: Record<string, string | number | boolean> = {
    query: input.query,

  };
  return executeWorkflow({
    workflow: WORKFLOW,
    params,
    credentials: opts.credentials,
    fetchImpl: opts.fetchImpl,
    initialState: opts.initialState,
    workflowPath: join(__dirname, 'workflow.json'),
  });
}

export { WORKFLOW };
