'use strict';

// Ages are fixed server-side, never taken from the frontend.
const AGE_BY_TYPE = { ADT: 25, CNN: 10, INF: 1 };
const ageFor = (type) => (AGE_BY_TYPE[type] !== undefined ? AGE_BY_TYPE[type] : null);

const buildCpoRequest = ({ legs, passengers }) => ({
  flights: legs.map((leg) => ({ from: leg.origin, to: leg.destination, departureDate: leg.departureDate })),
  passengers: passengers.map((p) => ({ type: p.type, count: p.count, age: ageFor(p.type) })),
  rawResponse: true,
});

const buildLfsRequest = ({ legs, passengers }) => ({
  legs: legs.map((leg) => ({ origin: leg.origin, destination: leg.destination, departureDate: leg.departureDate })),
  passengers: passengers.map((p) => ({ code: p.type, count: p.count, age: ageFor(p.type) })),
});

module.exports = { buildCpoRequest, buildLfsRequest };