const { randomUUID } = require("crypto");

module.exports = ({ carrier, flightNumber, date }) => {
  // Base64-encoded UUID as required by Travelport
  const key = Buffer.from(randomUUID()).toString("base64");

  return `
<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:air="http://www.travelport.com/schema/air_v54_0"
  xmlns:com="http://www.travelport.com/schema/common_v54_0">

  <soapenv:Header/>

  <soapenv:Body>
    <air:FlightInformationReq
      TraceId="FLTINFO_${carrier}${flightNumber}_${date}"
      TargetBranch="${process.env.TARGET_BRANCH}">

      <com:BillingPointOfSaleInfo OriginApplication="UAPI"/>

      <air:FlightInfoCriteria
        Key="${key}"
        Carrier="${carrier}"
        FlightNumber="${flightNumber}"
        DepartureDate="${date}" />

    </air:FlightInformationReq>
  </soapenv:Body>
</soapenv:Envelope>
`.trim();
};
