"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("./orgDomains-W_rFTMBa.cjs");
async function assignmentReasonHandler({
  recordType,
  teamMemberEmail,
  routingFormResponseId,
  recordId
}) {
  const returnObject = { reasonEnum: index.AssignmentReasonEnum.SALESFORCE_ASSIGNMENT };
  switch (recordType) {
    case index.SalesforceRecordEnum.CONTACT:
      return {
        ...returnObject,
        assignmentReason: `Salesforce contact owner: ${teamMemberEmail}${recordId ? ` (Contact ID: ${recordId})` : ""}`
      };
    case index.SalesforceRecordEnum.LEAD:
      return {
        ...returnObject,
        assignmentReason: `Salesforce lead owner: ${teamMemberEmail}${recordId ? ` (Lead ID: ${recordId})` : ""}`
      };
    case index.SalesforceRecordEnum.ACCOUNT:
      return {
        ...returnObject,
        assignmentReason: `Salesforce account owner: ${teamMemberEmail}${recordId ? ` (Account ID: ${recordId})` : ""}`
      };
    case index.RoutingReasons.ACCOUNT_LOOKUP_FIELD:
      const assignmentReason = await handleAccountLookupFieldReason(
        routingFormResponseId,
        teamMemberEmail,
        recordId
      );
      return { ...returnObject, assignmentReason };
  }
}
async function handleAccountLookupFieldReason(routingFormResponseId, teamMemberEmail, recordId) {
  const routingFormResponse = await index.prisma.app_RoutingForms_FormResponse.findUnique({
    where: {
      id: routingFormResponseId
    },
    select: {
      chosenRouteId: true,
      form: {
        select: {
          routes: true
        }
      }
    }
  });
  if (!routingFormResponse)
    return;
  const { form } = routingFormResponse;
  if (!form.routes)
    return;
  const parsedRoutes = index.zodRoutes.safeParse(form.routes);
  if (!parsedRoutes.success || !parsedRoutes.data)
    return;
  const chosenRouteId = routingFormResponse.chosenRouteId;
  const takenRoute = parsedRoutes.data.find((route) => route.id === chosenRouteId);
  if (!takenRoute || !("attributeRoutingConfig" in takenRoute))
    return;
  const attributeRoutingConfig = takenRoute?.attributeRoutingConfig;
  if (!attributeRoutingConfig)
    return;
  const salesforceConfig = attributeRoutingConfig["salesforce"];
  const accountLookupFieldName = salesforceConfig?.rrSKipToAccountLookupFieldName;
  return accountLookupFieldName ? `Salesforce account lookup field: ${accountLookupFieldName} - ${teamMemberEmail}${recordId ? ` (Account ID: ${recordId})` : ""}` : void 0;
}
const appBookingFormHandler = {
  salesforce: assignmentReasonHandler
};
exports.default = appBookingFormHandler;
