const buildAddItemRequestXML = (itemDetails) => {
  // Constructing the XML payload using template literals
  return `<?xml version="1.0" encoding="utf-8"?>
  <AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
    <RequesterCredentials>
      <eBayAuthToken>${itemDetails.userToken}</eBayAuthToken>
    </RequesterCredentials>
    <Item>
      <Title>${itemDetails.title}</Title>
      <Description><![CDATA[${itemDetails.description}]]></Description>
      <PrimaryCategory>
        <CategoryID>${itemDetails.categoryID}</CategoryID>
      </PrimaryCategory>
      <StartPrice>${itemDetails.startPrice}</StartPrice>
      <ConditionID>${itemDetails.conditionID}</ConditionID>
      <Country>${itemDetails.country}</Country>
      <Currency>${itemDetails.currency}</Currency>
      <DispatchTimeMax>${itemDetails.dispatchTimeMax}</DispatchTimeMax>
      <ListingDuration>${itemDetails.listingDuration}</ListingDuration>
      <ListingType>${itemDetails.listingType}</ListingType>
      <PaymentMethods>${itemDetails.paymentMethods}</PaymentMethods>
      <PayPalEmailAddress>${itemDetails.payPalEmailAddress}</PayPalEmailAddress>
      <PictureDetails>
        ${itemDetails.imageURLs
          .map((url) => `<PictureURL>${url}</PictureURL>`)
          .join("")}
      </PictureDetails>
      <PostalCode>${itemDetails.postalCode}</PostalCode>
      <Quantity>${itemDetails.quantity}</Quantity>
      <ReturnPolicy>
        <ReturnsAcceptedOption>${
          itemDetails.returnsAcceptedOption
        }</ReturnsAcceptedOption>
        <RefundOption>${itemDetails.refundOption}</RefundOption>
        <ReturnsWithinOption>${
          itemDetails.returnsWithinOption
        }</ReturnsWithinOption>
        <Description>${itemDetails.returnPolicyDescription}</Description>
        <ShippingCostPaidByOption>${
          itemDetails.shippingCostPaidByOption
        }</ShippingCostPaidByOption>
      </ReturnPolicy>
      <ShippingDetails>
        <ShippingType>${itemDetails.shippingType}</ShippingType>
        <ShippingServiceOptions>
          <ShippingServicePriority>1</ShippingServicePriority>
          <ShippingService>${itemDetails.shippingService}</ShippingService>
          <ShippingServiceCost>${
            itemDetails.shippingServiceCost
          }</ShippingServiceCost>
        </ShippingServiceOptions>
      </ShippingDetails>
      <Site>${itemDetails.site}</Site>
    </Item>
  </AddItemRequest>`;
};

export default buildAddItemRequestXML;
