"use strict";
const z = require("zod");
const index = require("./i18n-HHdcQbuJ.cjs");
const eventTypeAppCardZod = z.z.object({
  enabled: z.z.boolean().optional(),
  credentialId: z.z.number().optional(),
  appCategories: z.z.array(z.z.string()).optional()
});
z.z.object({});
var SalesforceRecordEnum = /* @__PURE__ */ ((SalesforceRecordEnum2) => {
  SalesforceRecordEnum2["CONTACT"] = "Contact";
  SalesforceRecordEnum2["LEAD"] = "Lead";
  SalesforceRecordEnum2["ACCOUNT"] = "Account";
  SalesforceRecordEnum2["EVENT"] = "Event";
  return SalesforceRecordEnum2;
})(SalesforceRecordEnum || {});
var WhenToWriteToRecord = /* @__PURE__ */ ((WhenToWriteToRecord2) => {
  WhenToWriteToRecord2["EVERY_BOOKING"] = "every_booking";
  WhenToWriteToRecord2["FIELD_EMPTY"] = "field_empty";
  return WhenToWriteToRecord2;
})(WhenToWriteToRecord || {});
var SalesforceFieldType = /* @__PURE__ */ ((SalesforceFieldType2) => {
  SalesforceFieldType2["DATE"] = "date";
  SalesforceFieldType2["TEXT"] = "string";
  SalesforceFieldType2["PHONE"] = "phone";
  SalesforceFieldType2["CUSTOM"] = "custom";
  SalesforceFieldType2["PICKLIST"] = "picklist";
  SalesforceFieldType2["CHECKBOX"] = "boolean";
  SalesforceFieldType2["DATETIME"] = "datetime";
  SalesforceFieldType2["TEXTAREA"] = "textarea";
  return SalesforceFieldType2;
})(SalesforceFieldType || {});
var DateFieldTypeData = /* @__PURE__ */ ((DateFieldTypeData2) => {
  DateFieldTypeData2["BOOKING_START_DATE"] = "booking_start_date";
  DateFieldTypeData2["BOOKING_CREATED_DATE"] = "booking_created_date";
  DateFieldTypeData2["BOOKING_CANCEL_DATE"] = "booking_cancel_date";
  return DateFieldTypeData2;
})(DateFieldTypeData || {});
var RoutingReasons = /* @__PURE__ */ ((RoutingReasons2) => {
  RoutingReasons2["ACCOUNT_LOOKUP_FIELD"] = "account_lookup_field";
  RoutingReasons2["LEAD_OWNER"] = "lead_owner";
  RoutingReasons2["CONTACT_OWNER"] = "contact_owner";
  RoutingReasons2["ACCOUNT_OWNER"] = "account_owner";
  return RoutingReasons2;
})(RoutingReasons || {});
const writeToBookingEntry = z.z.object({
  value: z.z.union([z.z.string(), z.z.boolean()]),
  fieldType: z.z.nativeEnum(SalesforceFieldType),
  whenToWrite: z.z.nativeEnum(WhenToWriteToRecord)
});
z.z.object({
  field: z.z.string(),
  fieldType: z.z.nativeEnum(SalesforceFieldType),
  value: z.z.union([z.z.string(), z.z.boolean()]),
  whenToWrite: z.z.nativeEnum(WhenToWriteToRecord)
});
const writeToRecordDataSchema = z.z.record(z.z.string(), writeToBookingEntry);
const routingFormOptions = z.z.object({
  rrSkipToAccountLookupField: z.z.boolean().optional(),
  rrSKipToAccountLookupFieldName: z.z.string().optional()
}).optional();
z.z.object({
  writeToRecordObject: writeToRecordDataSchema.optional()
});
z.z.any().refine((val) => typeof val === "boolean" || val === void 0).optional();
const appDataSchema$1 = eventTypeAppCardZod.extend({
  roundRobinLeadSkip: z.z.boolean().optional(),
  roundRobinSkipCheckRecordOn: z.z.nativeEnum(SalesforceRecordEnum).default(SalesforceRecordEnum.CONTACT).optional(),
  ifFreeEmailDomainSkipOwnerCheck: z.z.boolean().optional(),
  roundRobinSkipFallbackToLeadOwner: z.z.boolean().optional(),
  skipContactCreation: z.z.boolean().optional(),
  createEventOn: z.z.nativeEnum(SalesforceRecordEnum).default(SalesforceRecordEnum.CONTACT).optional(),
  createNewContactUnderAccount: z.z.boolean().optional(),
  createLeadIfAccountNull: z.z.boolean().optional(),
  onBookingWriteToEventObject: z.z.boolean().optional(),
  onBookingWriteToEventObjectMap: z.z.record(z.z.any()).optional(),
  createEventOnLeadCheckForContact: z.z.boolean().optional(),
  onBookingChangeRecordOwner: z.z.boolean().optional(),
  onBookingChangeRecordOwnerName: z.z.string().optional(),
  sendNoShowAttendeeData: z.z.boolean().optional(),
  sendNoShowAttendeeDataField: z.z.string().optional(),
  onBookingWriteToRecord: z.z.boolean().optional(),
  onBookingWriteToRecordFields: z.z.record(z.z.string(), writeToBookingEntry).optional(),
  ignoreGuests: z.z.boolean().optional(),
  onCancelWriteToEventRecord: z.z.boolean().optional(),
  onCancelWriteToEventRecordFields: z.z.record(z.z.string(), writeToBookingEntry).optional()
});
z.z.object({
  consumer_key: z.z.string().min(1),
  consumer_secret: z.z.string().min(1)
});
const routingFormAppDataSchemas = {
  salesforce: routingFormOptions
};
const zodNonRouterField = z.z.object({
  id: z.z.string(),
  label: z.z.string(),
  identifier: z.z.string().optional(),
  placeholder: z.z.string().optional(),
  type: z.z.string(),
  /**
   * @deprecated in favour of `options`
   */
  selectText: z.z.string().optional(),
  required: z.z.boolean().optional(),
  deleted: z.z.boolean().optional(),
  options: z.z.array(
    z.z.object({
      label: z.z.string(),
      // To keep backwards compatibility with the options generated from legacy selectText, we allow saving null as id
      // It helps in differentiating whether the routing logic should consider the option.label as value or option.id as value.
      // This is important for legacy routes which has option.label saved in conditions and it must keep matching with the value of the option
      id: z.z.string().or(z.z.null())
    })
  ).optional()
});
const zodRouterField = zodNonRouterField.extend({
  routerId: z.z.string()
});
const zodField = z.z.union([zodRouterField, zodNonRouterField]);
const zodFields = z.z.array(zodField).optional();
const zodNonRouterFieldView = zodNonRouterField;
const zodRouterFieldView = zodRouterField.extend({
  routerField: zodNonRouterFieldView,
  router: z.z.object({
    name: z.z.string(),
    description: z.z.string(),
    id: z.z.string()
  })
});
const zodFieldView = z.z.union([zodNonRouterFieldView, zodRouterFieldView]);
z.z.array(zodFieldView).optional();
var RouteActionType = /* @__PURE__ */ ((RouteActionType2) => {
  RouteActionType2["CustomPageMessage"] = "customPageMessage";
  RouteActionType2["ExternalRedirectUrl"] = "externalRedirectUrl";
  RouteActionType2["EventTypeRedirectUrl"] = "eventTypeRedirectUrl";
  return RouteActionType2;
})(RouteActionType || {});
const routeActionTypeSchema = z.z.nativeEnum(RouteActionType);
const attributeRoutingConfigSchema = z.z.object({
  skipContactOwner: z.z.boolean().optional(),
  salesforce: routingFormAppDataSchemas["salesforce"]
}).nullish();
const zodNonRouterRoute = z.z.object({
  id: z.z.string(),
  name: z.z.string().optional(),
  attributeIdForWeights: z.z.string().optional(),
  attributeRoutingConfig: attributeRoutingConfigSchema,
  // TODO: It should be renamed to formFieldsQueryValue but it would take some effort
  /**
   * RAQB query value for form fields
   * BRANDED to ensure we don't give it Attributes
   */
  queryValue: index.raqbQueryValueSchema.brand(),
  /**
   * RAQB query value for attributes. It is only applicable for Team Events as it is used to find matching team members
   * BRANDED to ensure we don't give it Form Fields
   */
  attributesQueryValue: index.raqbQueryValueSchema.optional(),
  /**
   * RAQB query value for fallback of `attributesQueryValue`
   * BRANDED to ensure we don't give it Form Fields, It needs Attributes
   */
  fallbackAttributesQueryValue: index.raqbQueryValueSchema.optional(),
  /**
   * Whether the route is a fallback if no other routes match
   */
  isFallback: z.z.boolean().optional(),
  action: z.z.object({
    type: routeActionTypeSchema,
    eventTypeId: z.z.number().optional(),
    value: z.z.string()
  })
});
const zodNonRouterRouteView = zodNonRouterRoute;
const zodRouterRoute = z.z.object({
  // This is the id of the Form being used as router
  id: z.z.string(),
  name: z.z.string().optional(),
  isRouter: z.z.literal(true)
});
const zodRoute = z.z.union([zodNonRouterRoute, zodRouterRoute]);
const zodRouterRouteView = zodRouterRoute.extend({
  //TODO: Extend it from form
  name: z.z.string(),
  description: z.z.string().nullable(),
  routes: z.z.array(z.z.union([zodRoute, z.z.null()]))
});
const zodRoutes = z.z.union([z.z.array(zodRoute), z.z.null()]).optional();
const zodRouteView = z.z.union([zodNonRouterRouteView, zodRouterRouteView]);
z.z.union([z.z.array(zodRouteView), z.z.null()]).optional();
const appDataSchema = z.z.any();
z.z.object({});
const routingFormResponseInDbSchema = z.z.record(
  z.z.object({
    label: z.z.string().optional(),
    value: z.z.union([z.z.string(), z.z.number(), z.z.array(z.z.string())])
  })
);
exports.DateFieldTypeData = DateFieldTypeData;
exports.RoutingReasons = RoutingReasons;
exports.SalesforceFieldType = SalesforceFieldType;
exports.SalesforceRecordEnum = SalesforceRecordEnum;
exports.WhenToWriteToRecord = WhenToWriteToRecord;
exports.appDataSchema = appDataSchema;
exports.appDataSchema$1 = appDataSchema$1;
exports.eventTypeAppCardZod = eventTypeAppCardZod;
exports.routingFormResponseInDbSchema = routingFormResponseInDbSchema;
exports.zodFields = zodFields;
exports.zodNonRouterField = zodNonRouterField;
exports.zodRoutes = zodRoutes;
