import { FareOption } from "../../types/flights"; import { buildSeed } from "../seed/build-seed"; import { procedurallyGetBoolean } from "../seed/procedurally-get-boolean"; import { procedurallyGetIntegerBetween } from "../seed/procedurally-get-integer-between"; import { procedurallyGetUuidV4 } from "../seed/procedurally-get-uuid-v4"; import { procedurallyPickItemFrom } from "../seed/procedurally-pick-item-from"; interface GetFareOptionsOptions { tileSeed: number; tileTier: "1" | "2" | "3" | "4" | "5"; tileTitle: string; } interface GenerateFareOptionOptions { tileSeed: number; tileTier: "1" | "2" | "3" | "4" | "5"; tileTitle: string; fareIndex: number; } const priceRangesByTileTier = { 1: [100, 550], 2: [140, 700], 3: [300, 1200], 4: [900, 4000], 5: [3500, 15000], }; const generateFareOption = ({ tileSeed, tileTier, tileTitle, fareIndex, }: GenerateFareOptionOptions) => { const fareSeed = buildSeed(`${tileSeed}-${fareIndex}-fare-generator`); // const multiplier = isInternational ? 1.5 : 1; const multiplier = 1; // TODO: consider airline fanciness, national vs international, etc const priceRange = priceRangesByTileTier[tileTier]; const priceInUSD = procedurallyGetIntegerBetween( fareSeed, Math.floor(priceRange[0] * multiplier), Math.floor(priceRange[1] * multiplier) ); const fareOption = { id: procedurallyGetUuidV4(fareSeed), name: tileTitle, // TODO: dynamic price according to airline fanciness and maybe other tile info priceInUSD, refundPolicy: procedurallyPickItemFrom(fareSeed, ["free", "fee", "no"]), changePolicy: procedurallyPickItemFrom(fareSeed, ["free", "fee", "no"]), checkedBagsIncluded: procedurallyGetIntegerBetween(fareSeed, 0, 2), hasMealService: procedurallyGetBoolean(fareSeed, 50), // TODO: dynamic features according to airline and tile features: ["Free checked bags"], } satisfies FareOption; return fareOption; }; export const getFareOptions = ({ tileSeed, tileTier, tileTitle, }: GetFareOptionsOptions) => { const fareOptionsAmount = procedurallyGetIntegerBetween(tileSeed, 1, 3); const fareOptions = Array.from({ length: fareOptionsAmount }) .fill(null) .map((_, fareIndex) => generateFareOption({ tileSeed, tileTier, tileTitle, fareIndex, }) ); return fareOptions satisfies FareOption[]; };