/**
 * GENERATED by `imprint emit` — DO NOT EDIT BY HAND.
 *
 * Tool: search_hotels
 * Site: google-hotels
 * Intent: Search Google Hotels for a location and date range with optional filters (price, rating, amenities, star class, brands, sort, property type).
 *
 * To regenerate: imprint emit ~/.imprint/google-hotels/search_hotels/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": "search_hotels",
  "intent": {
    "description": "Search Google Hotels for a location and date range with optional filters (price, rating, amenities, star class, brands, sort, property type).",
    "userSaid": "searched for hotels at chicago loop from july 3-6; filtered for > 4.0 rating; filtered min and max price; added amenities; added 2/4/5 star; added brand filters; sorted by lowest price, highest rating, most reviewed; changed property type to vacation rentals; changed location to tahoe city and denver downtown"
  },
  "parameters": [
    {
      "name": "location",
      "type": "string",
      "description": "Destination query, e.g. 'chicago loop', 'tahoe city', 'denver downtown'",
      "default": "chicago loop",
      "verified": true
    },
    {
      "name": "check_in_date",
      "type": "string",
      "description": "Check-in date (YYYY-MM-DD)",
      "default": "2026-07-03",
      "verified": false,
      "verifyNote": "annotated"
    },
    {
      "name": "check_out_date",
      "type": "string",
      "description": "Check-out date (YYYY-MM-DD)",
      "default": "2026-07-06",
      "verified": false,
      "verifyNote": "annotated"
    },
    {
      "name": "adults",
      "type": "number",
      "description": "Number of adult travelers",
      "default": 2,
      "verified": false,
      "verifyNote": "annotated"
    },
    {
      "name": "children",
      "type": "number",
      "description": "Number of child travelers",
      "default": 0,
      "verified": false,
      "verifyNote": "annotated"
    },
    {
      "name": "min_rating",
      "type": "number",
      "description": "Minimum guest rating filter, e.g. 4.0 (0 = no filter)",
      "default": 0,
      "verified": false,
      "verifyNote": "annotated"
    },
    {
      "name": "min_price",
      "type": "number",
      "description": "Minimum nightly price filter (0 = no filter)",
      "default": 0,
      "verified": false,
      "verifyNote": "annotated"
    },
    {
      "name": "max_price",
      "type": "number",
      "description": "Maximum nightly price filter, e.g. 338 (0 = no filter)",
      "default": 0,
      "verified": true
    },
    {
      "name": "amenities",
      "type": "string",
      "description": "Comma-separated amenity names or codes (e.g. 'free wi-fi,pool' or '6,9'); empty = no filter",
      "default": "",
      "verified": false,
      "verifyNote": "annotated"
    },
    {
      "name": "hotel_class",
      "type": "string",
      "description": "Comma-separated star classes, e.g. '2,3' or '4,5'; empty = no filter",
      "default": "",
      "verified": true
    },
    {
      "name": "brands",
      "type": "string",
      "description": "Comma-separated brand codes ('parent:child' or numeric); empty = no filter",
      "default": "",
      "verified": false,
      "verifyNote": "annotated"
    },
    {
      "name": "sort_by",
      "type": "string",
      "description": "Sort order: relevance | lowest_price | highest_rating | most_reviewed",
      "default": "relevance",
      "verified": true
    },
    {
      "name": "property_type",
      "type": "string",
      "description": "hotels | vacation_rentals",
      "default": "hotels",
      "verified": true
    }
  ],
  "requests": [
    {
      "method": "POST",
      "url": "https://www.google.com/_/TravelFrontendUi/data/batchexecute?rpcids=AtySUc&source-path=%2Ftravel%2Fsearch&f.sid=7513562915459271421&bl=boq_travel-frontend-ui_20260527.01_p0&hl=en-US&soc-app=162&soc-platform=1&soc-device=1&_reqid=2252256&rt=c",
      "headers": {
        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "X-Same-Domain": "1",
        "x-goog-ext-259736195-jspb": "[\"en-US\",\"US\",\"USD\",2,null,[420],null,null,7,[]]",
        "x-goog-ext-190139975-jspb": "[\"US\",\"ZZ\",\"x6c25Q==\"]",
        "Referer": "https://www.google.com/travel/search"
      },
      "body": "f.req={\"location\":\"${param.location}\",\"check_in_date\":\"${param.check_in_date}\",\"check_out_date\":\"${param.check_out_date}\",\"adults\":\"${param.adults}\",\"children\":\"${param.children}\",\"min_rating\":\"${param.min_rating}\",\"min_price\":\"${param.min_price}\",\"max_price\":\"${param.max_price}\",\"amenities\":\"${param.amenities}\",\"hotel_class\":\"${param.hotel_class}\",\"brands\":\"${param.brands}\",\"sort_by\":\"${param.sort_by}\",\"property_type\":\"${param.property_type}\"}",
      "effect": "safe"
    }
  ],
  "site": "google-hotels",
  "parserModule": "./parser.ts",
  "requestTransformModule": "./request-transform.ts",
  "liveVerified": true
};

export interface SearchHotelsInput {
  /** Destination query, e.g. 'chicago loop', 'tahoe city', 'denver downtown' */
  location?: string;
  /** Check-in date (YYYY-MM-DD) */
  check_in_date?: string;
  /** Check-out date (YYYY-MM-DD) */
  check_out_date?: string;
  /** Number of adult travelers */
  adults?: number;
  /** Number of child travelers */
  children?: number;
  /** Minimum guest rating filter, e.g. 4.0 (0 = no filter) */
  min_rating?: number;
  /** Minimum nightly price filter (0 = no filter) */
  min_price?: number;
  /** Maximum nightly price filter, e.g. 338 (0 = no filter) */
  max_price?: number;
  /** Comma-separated amenity names or codes (e.g. 'free wi-fi,pool' or '6,9'); empty = no filter */
  amenities?: string;
  /** Comma-separated star classes, e.g. '2,3' or '4,5'; empty = no filter */
  hotel_class?: string;
  /** Comma-separated brand codes ('parent:child' or numeric); empty = no filter */
  brands?: string;
  /** Sort order: relevance | lowest_price | highest_rating | most_reviewed */
  sort_by?: string;
  /** hotels | vacation_rentals */
  property_type?: string;
}

export async function searchHotels(
  input: SearchHotelsInput,
  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> = {
    location: input.location ?? "chicago loop",
    check_in_date: input.check_in_date ?? "2026-07-03",
    check_out_date: input.check_out_date ?? "2026-07-06",
    adults: input.adults ?? 2,
    children: input.children ?? 0,
    min_rating: input.min_rating ?? 0,
    min_price: input.min_price ?? 0,
    max_price: input.max_price ?? 0,
    amenities: input.amenities ?? "",
    hotel_class: input.hotel_class ?? "",
    brands: input.brands ?? "",
    sort_by: input.sort_by ?? "relevance",
    property_type: input.property_type ?? "hotels",

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

export { WORKFLOW };
