const addQbxmlHeader = (xml) => {
  return `<?xml version="1.0" encoding="utf-8"?>
    <?qbxml version="13.0"?>
    ${xml}
    `;
};

exports.addQbxmlHeader = addQbxmlHeader;

exports.generateSourceTier = (jobs_by_pk) => {
  return jobs_by_pk.ins_co_nm && jobs_by_pk.ins_co_nm.trim().replace(":", " ");
};

exports.generateJobTier = (jobs_by_pk) => {
  return jobs_by_pk.ro_number && jobs_by_pk.ro_number.trim().replace(":", " ");
};

exports.generateOwnerTier = (jobs_by_pk, isThreeTier, twotierpref) => {
  if (isThreeTier) {
    //It's always gonna be the owner now. Same as 2 tier by name
    return (
      jobs_by_pk.ownr_co_nm
        ? `${jobs_by_pk.ownr_co_nm.substring(0, 30)} #${jobs_by_pk.owner.accountingid || ""}`
        : `${`${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""}`
            .substring(0, 30)
            .trim()} #${jobs_by_pk.owner.accountingid || ""}`
    )
      .trim()
      .replace(":", " ");
  } else {
    //What's the 2 tier pref?
    if (twotierpref === "source") {
      return this.generateSourceTier(jobs_by_pk);
      //It should be the insurance co.
    } else {
      //Same as 3 tier
      return (
        jobs_by_pk.ownr_co_nm
          ? `${jobs_by_pk.ownr_co_nm.substring(0, 30)} #${jobs_by_pk.owner.accountingid || ""}`
          : `${`${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""}`
              .substring(0, 30)
              .trim()} #${jobs_by_pk.owner.accountingid || ""}`
      )
        .trim()
        .replace(":", " ");
    }
  }
};
