import { z } from "zod";
import { O as raqbQueryValueSchema } from "./i18n-49-r55rr.js";
const eventTypeAppCardZod = z.object({
  enabled: z.boolean().optional(),
  credentialId: z.number().optional(),
  appCategories: z.array(z.string()).optional()
});
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.object({
  value: z.union([z.string(), z.boolean()]),
  fieldType: z.nativeEnum(SalesforceFieldType),
  whenToWrite: z.nativeEnum(WhenToWriteToRecord)
});
z.object({
  field: z.string(),
  fieldType: z.nativeEnum(SalesforceFieldType),
  value: z.union([z.string(), z.boolean()]),
  whenToWrite: z.nativeEnum(WhenToWriteToRecord)
});
const writeToRecordDataSchema = z.record(z.string(), writeToBookingEntry);
const routingFormOptions = z.object({
  rrSkipToAccountLookupField: z.boolean().optional(),
  rrSKipToAccountLookupFieldName: z.string().optional()
}).optional();
z.object({
  writeToRecordObject: writeToRecordDataSchema.optional()
});
z.any().refine((val) => typeof val === "boolean" || val === void 0).optional();
const appDataSchema$1 = eventTypeAppCardZod.extend({
  roundRobinLeadSkip: z.boolean().optional(),
  roundRobinSkipCheckRecordOn: z.nativeEnum(SalesforceRecordEnum).default(SalesforceRecordEnum.CONTACT).optional(),
  ifFreeEmailDomainSkipOwnerCheck: z.boolean().optional(),
  roundRobinSkipFallbackToLeadOwner: z.boolean().optional(),
  skipContactCreation: z.boolean().optional(),
  createEventOn: z.nativeEnum(SalesforceRecordEnum).default(SalesforceRecordEnum.CONTACT).optional(),
  createNewContactUnderAccount: z.boolean().optional(),
  createLeadIfAccountNull: z.boolean().optional(),
  onBookingWriteToEventObject: z.boolean().optional(),
  onBookingWriteToEventObjectMap: z.record(z.any()).optional(),
  createEventOnLeadCheckForContact: z.boolean().optional(),
  onBookingChangeRecordOwner: z.boolean().optional(),
  onBookingChangeRecordOwnerName: z.string().optional(),
  sendNoShowAttendeeData: z.boolean().optional(),
  sendNoShowAttendeeDataField: z.string().optional(),
  onBookingWriteToRecord: z.boolean().optional(),
  onBookingWriteToRecordFields: z.record(z.string(), writeToBookingEntry).optional(),
  ignoreGuests: z.boolean().optional(),
  onCancelWriteToEventRecord: z.boolean().optional(),
  onCancelWriteToEventRecordFields: z.record(z.string(), writeToBookingEntry).optional()
});
z.object({
  consumer_key: z.string().min(1),
  consumer_secret: z.string().min(1)
});
const routingFormAppDataSchemas = {
  salesforce: routingFormOptions
};
const zodNonRouterField = z.object({
  id: z.string(),
  label: z.string(),
  identifier: z.string().optional(),
  placeholder: z.string().optional(),
  type: z.string(),
  /**
   * @deprecated in favour of `options`
   */
  selectText: z.string().optional(),
  required: z.boolean().optional(),
  deleted: z.boolean().optional(),
  options: z.array(
    z.object({
      label: 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.string().or(z.null())
    })
  ).optional()
});
const zodRouterField = zodNonRouterField.extend({
  routerId: z.string()
});
const zodField = z.union([zodRouterField, zodNonRouterField]);
const zodFields = z.array(zodField).optional();
const zodNonRouterFieldView = zodNonRouterField;
const zodRouterFieldView = zodRouterField.extend({
  routerField: zodNonRouterFieldView,
  router: z.object({
    name: z.string(),
    description: z.string(),
    id: z.string()
  })
});
const zodFieldView = z.union([zodNonRouterFieldView, zodRouterFieldView]);
z.array(zodFieldView).optional();
var RouteActionType = /* @__PURE__ */ ((RouteActionType2) => {
  RouteActionType2["CustomPageMessage"] = "customPageMessage";
  RouteActionType2["ExternalRedirectUrl"] = "externalRedirectUrl";
  RouteActionType2["EventTypeRedirectUrl"] = "eventTypeRedirectUrl";
  return RouteActionType2;
})(RouteActionType || {});
const routeActionTypeSchema = z.nativeEnum(RouteActionType);
const attributeRoutingConfigSchema = z.object({
  skipContactOwner: z.boolean().optional(),
  salesforce: routingFormAppDataSchemas["salesforce"]
}).nullish();
const zodNonRouterRoute = z.object({
  id: z.string(),
  name: z.string().optional(),
  attributeIdForWeights: 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: 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: raqbQueryValueSchema.optional(),
  /**
   * RAQB query value for fallback of `attributesQueryValue`
   * BRANDED to ensure we don't give it Form Fields, It needs Attributes
   */
  fallbackAttributesQueryValue: raqbQueryValueSchema.optional(),
  /**
   * Whether the route is a fallback if no other routes match
   */
  isFallback: z.boolean().optional(),
  action: z.object({
    type: routeActionTypeSchema,
    eventTypeId: z.number().optional(),
    value: z.string()
  })
});
const zodNonRouterRouteView = zodNonRouterRoute;
const zodRouterRoute = z.object({
  // This is the id of the Form being used as router
  id: z.string(),
  name: z.string().optional(),
  isRouter: z.literal(true)
});
const zodRoute = z.union([zodNonRouterRoute, zodRouterRoute]);
const zodRouterRouteView = zodRouterRoute.extend({
  //TODO: Extend it from form
  name: z.string(),
  description: z.string().nullable(),
  routes: z.array(z.union([zodRoute, z.null()]))
});
const zodRoutes = z.union([z.array(zodRoute), z.null()]).optional();
const zodRouteView = z.union([zodNonRouterRouteView, zodRouterRouteView]);
z.union([z.array(zodRouteView), z.null()]).optional();
const appDataSchema = z.any();
z.object({});
const routingFormResponseInDbSchema = z.record(
  z.object({
    label: z.string().optional(),
    value: z.union([z.string(), z.number(), z.array(z.string())])
  })
);
export {
  DateFieldTypeData as D,
  RoutingReasons as R,
  SalesforceRecordEnum as S,
  WhenToWriteToRecord as W,
  zodNonRouterField as a,
  SalesforceFieldType as b,
  appDataSchema as c,
  appDataSchema$1 as d,
  eventTypeAppCardZod as e,
  zodFields as f,
  routingFormResponseInDbSchema as r,
  zodRoutes as z
};
