var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result) __defProp(target, key, result);
  return result;
};
import { OptionalProps } from "@mikro-orm/core";
import { Check, Entity, Index, PrimaryKey, Property, Unique } from "@mikro-orm/decorators/legacy";
OptionalProps;
let CommunicationChannel = class {
  constructor() {
    this.isActive = true;
    this.isPrimary = false;
    this.status = "connected";
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CommunicationChannel.prototype, "id", 2);
__decorateClass([
  Property({ name: "provider_key", type: "text" })
], CommunicationChannel.prototype, "providerKey", 2);
__decorateClass([
  Property({ name: "channel_type", type: "text" })
], CommunicationChannel.prototype, "channelType", 2);
__decorateClass([
  Property({ name: "display_name", type: "text" })
], CommunicationChannel.prototype, "displayName", 2);
__decorateClass([
  Property({ name: "external_identifier", type: "text", nullable: true })
], CommunicationChannel.prototype, "externalIdentifier", 2);
__decorateClass([
  Property({ name: "credentials_ref", type: "uuid", nullable: true })
], CommunicationChannel.prototype, "credentialsRef", 2);
__decorateClass([
  Property({ name: "capabilities", type: "json", nullable: true })
], CommunicationChannel.prototype, "capabilities", 2);
__decorateClass([
  Property({ name: "is_active", type: "boolean", default: true })
], CommunicationChannel.prototype, "isActive", 2);
__decorateClass([
  Property({ name: "user_id", type: "uuid", nullable: true })
], CommunicationChannel.prototype, "userId", 2);
__decorateClass([
  Property({ name: "is_primary", type: "boolean", default: false })
], CommunicationChannel.prototype, "isPrimary", 2);
__decorateClass([
  Property({ name: "poll_interval_seconds", type: "int", nullable: true })
], CommunicationChannel.prototype, "pollIntervalSeconds", 2);
__decorateClass([
  Property({ name: "last_polled_at", type: Date, nullable: true })
], CommunicationChannel.prototype, "lastPolledAt", 2);
__decorateClass([
  Property({ name: "status", type: "text", default: "connected" })
], CommunicationChannel.prototype, "status", 2);
__decorateClass([
  Property({ name: "last_error", type: "text", nullable: true })
], CommunicationChannel.prototype, "lastError", 2);
__decorateClass([
  Property({ name: "channel_state", type: "json", nullable: true })
], CommunicationChannel.prototype, "channelState", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], CommunicationChannel.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], CommunicationChannel.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CommunicationChannel.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], CommunicationChannel.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], CommunicationChannel.prototype, "deletedAt", 2);
CommunicationChannel = __decorateClass([
  Entity({ tableName: "communication_channels" }),
  Index({ name: "communication_channels_tenant_provider_idx", properties: ["tenantId", "providerKey"] }),
  Index({
    name: "communication_channels_provider_external_idx",
    expression: `create index "communication_channels_provider_external_idx" on "communication_channels" ("provider_key", "external_identifier") where "deleted_at" is null`
  }),
  Index({ name: "communication_channels_tenant_type_active_idx", properties: ["tenantId", "channelType", "isActive"] }),
  Index({
    name: "communication_channels_user_lookup_idx",
    properties: ["userId", "channelType", "deletedAt"]
  }),
  Index({
    name: "communication_channels_poll_due_idx",
    expression: `create index "communication_channels_poll_due_idx" on "communication_channels" ("is_active", "last_polled_at") where "deleted_at" is null`
  }),
  Index({
    name: "communication_channels_one_primary_per_user_uq",
    expression: `create unique index "communication_channels_one_primary_per_user_uq" on "communication_channels" ("user_id") where "is_primary" and "user_id" is not null and "deleted_at" is null`
  }),
  Index({
    name: "communication_channels_user_provider_external_uq",
    expression: `create unique index "communication_channels_user_provider_external_uq" on "communication_channels" ("tenant_id", "user_id", "provider_key", "external_identifier") where "deleted_at" is null and "user_id" is not null and "external_identifier" is not null`
  })
], CommunicationChannel);
OptionalProps;
let ExternalConversation = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], ExternalConversation.prototype, "id", 2);
__decorateClass([
  Property({ name: "channel_id", type: "uuid" })
], ExternalConversation.prototype, "channelId", 2);
__decorateClass([
  Property({ name: "external_conversation_id", type: "text" })
], ExternalConversation.prototype, "externalConversationId", 2);
__decorateClass([
  Property({ name: "subject", type: "text", nullable: true })
], ExternalConversation.prototype, "subject", 2);
__decorateClass([
  Property({ name: "contact_person_id", type: "uuid", nullable: true })
], ExternalConversation.prototype, "contactPersonId", 2);
__decorateClass([
  Property({ name: "assigned_user_id", type: "uuid", nullable: true })
], ExternalConversation.prototype, "assignedUserId", 2);
__decorateClass([
  Property({ name: "last_message_at", type: Date, nullable: true })
], ExternalConversation.prototype, "lastMessageAt", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], ExternalConversation.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], ExternalConversation.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], ExternalConversation.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], ExternalConversation.prototype, "updatedAt", 2);
ExternalConversation = __decorateClass([
  Entity({ tableName: "external_conversations" }),
  Index({ name: "external_conversations_channel_idx", properties: ["channelId", "externalConversationId"] }),
  Index({ name: "external_conversations_contact_person_idx", properties: ["contactPersonId"] }),
  Index({ name: "external_conversations_assigned_user_idx", properties: ["assignedUserId"] }),
  Unique({ name: "external_conversations_channel_external_uq", properties: ["channelId", "externalConversationId"] })
], ExternalConversation);
OptionalProps;
let ExternalMessage = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], ExternalMessage.prototype, "id", 2);
__decorateClass([
  Property({ name: "channel_id", type: "uuid" })
], ExternalMessage.prototype, "channelId", 2);
__decorateClass([
  Property({ name: "conversation_id", type: "uuid" })
], ExternalMessage.prototype, "conversationId", 2);
__decorateClass([
  Property({ name: "external_message_id", type: "text" })
], ExternalMessage.prototype, "externalMessageId", 2);
__decorateClass([
  Property({ name: "direction", type: "text" })
], ExternalMessage.prototype, "direction", 2);
__decorateClass([
  Property({ name: "sender_identifier", type: "text", nullable: true })
], ExternalMessage.prototype, "senderIdentifier", 2);
__decorateClass([
  Property({ name: "sender_display_name", type: "text", nullable: true })
], ExternalMessage.prototype, "senderDisplayName", 2);
__decorateClass([
  Property({ name: "provider_timestamp", type: Date, nullable: true })
], ExternalMessage.prototype, "providerTimestamp", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], ExternalMessage.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], ExternalMessage.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], ExternalMessage.prototype, "createdAt", 2);
ExternalMessage = __decorateClass([
  Entity({ tableName: "external_messages" }),
  Index({ name: "external_messages_conversation_idx", properties: ["conversationId"] }),
  Index({ name: "external_messages_channel_external_idx", properties: ["channelId", "externalMessageId"] }),
  Unique({ name: "external_messages_channel_external_uq", properties: ["channelId", "externalMessageId"] })
], ExternalMessage);
OptionalProps;
let MessageChannelLink = class {
  constructor() {
    this.deliveryStatus = "pending";
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], MessageChannelLink.prototype, "id", 2);
__decorateClass([
  Property({ name: "message_id", type: "uuid" })
], MessageChannelLink.prototype, "messageId", 2);
__decorateClass([
  Property({ name: "external_conversation_id", type: "uuid" })
], MessageChannelLink.prototype, "externalConversationId", 2);
__decorateClass([
  Property({ name: "external_message_id", type: "uuid", nullable: true })
], MessageChannelLink.prototype, "externalMessageId", 2);
__decorateClass([
  Property({ name: "provider_key", type: "text" })
], MessageChannelLink.prototype, "providerKey", 2);
__decorateClass([
  Property({ name: "channel_type", type: "text" })
], MessageChannelLink.prototype, "channelType", 2);
__decorateClass([
  Property({ name: "direction", type: "text" })
], MessageChannelLink.prototype, "direction", 2);
__decorateClass([
  Property({ name: "delivery_status", type: "text" })
], MessageChannelLink.prototype, "deliveryStatus", 2);
__decorateClass([
  Property({ name: "channel_payload", type: "json", nullable: true })
], MessageChannelLink.prototype, "channelPayload", 2);
__decorateClass([
  Property({ name: "channel_content_type", type: "text", nullable: true })
], MessageChannelLink.prototype, "channelContentType", 2);
__decorateClass([
  Property({ name: "interactive_state", type: "json", nullable: true })
], MessageChannelLink.prototype, "interactiveState", 2);
__decorateClass([
  Property({ name: "channel_metadata", type: "json", nullable: true })
], MessageChannelLink.prototype, "channelMetadata", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], MessageChannelLink.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], MessageChannelLink.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], MessageChannelLink.prototype, "createdAt", 2);
MessageChannelLink = __decorateClass([
  Entity({ tableName: "message_channel_links" }),
  Index({ name: "message_channel_links_message_idx", properties: ["messageId"] }),
  Index({ name: "message_channel_links_ext_conv_idx", properties: ["externalConversationId"] }),
  Index({ name: "message_channel_links_ext_msg_idx", properties: ["externalMessageId"] }),
  Unique({ name: "message_channel_links_message_uq", properties: ["messageId"] })
], MessageChannelLink);
OptionalProps;
let ChannelThreadMapping = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], ChannelThreadMapping.prototype, "id", 2);
__decorateClass([
  Property({ name: "external_conversation_id", type: "uuid" })
], ChannelThreadMapping.prototype, "externalConversationId", 2);
__decorateClass([
  Property({ name: "message_thread_id", type: "uuid" })
], ChannelThreadMapping.prototype, "messageThreadId", 2);
__decorateClass([
  Property({ name: "channel_id", type: "uuid" })
], ChannelThreadMapping.prototype, "channelId", 2);
__decorateClass([
  Property({ name: "provider_key", type: "text" })
], ChannelThreadMapping.prototype, "providerKey", 2);
__decorateClass([
  Property({ name: "external_thread_ref", type: "text" })
], ChannelThreadMapping.prototype, "externalThreadRef", 2);
__decorateClass([
  Property({ name: "assigned_user_id", type: "uuid", nullable: true })
], ChannelThreadMapping.prototype, "assignedUserId", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], ChannelThreadMapping.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], ChannelThreadMapping.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], ChannelThreadMapping.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], ChannelThreadMapping.prototype, "updatedAt", 2);
ChannelThreadMapping = __decorateClass([
  Entity({ tableName: "channel_thread_mappings" }),
  Index({ name: "channel_thread_mappings_ext_conv_idx", properties: ["externalConversationId", "tenantId"] }),
  Index({ name: "channel_thread_mappings_thread_idx", properties: ["messageThreadId", "tenantId"] }),
  Unique({ name: "channel_thread_mappings_ext_conv_uq", properties: ["externalConversationId", "tenantId"] })
], ChannelThreadMapping);
OptionalProps;
let MessageReaction = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], MessageReaction.prototype, "id", 2);
__decorateClass([
  Property({ name: "message_id", type: "uuid" })
], MessageReaction.prototype, "messageId", 2);
__decorateClass([
  Property({ name: "emoji", type: "text" })
], MessageReaction.prototype, "emoji", 2);
__decorateClass([
  Property({ name: "reacted_by_user_id", type: "uuid", nullable: true })
], MessageReaction.prototype, "reactedByUserId", 2);
__decorateClass([
  Property({ name: "reacted_by_external_id", type: "text", nullable: true })
], MessageReaction.prototype, "reactedByExternalId", 2);
__decorateClass([
  Property({ name: "reacted_by_display_name", type: "text", nullable: true })
], MessageReaction.prototype, "reactedByDisplayName", 2);
__decorateClass([
  Property({ name: "provider_key", type: "text", nullable: true })
], MessageReaction.prototype, "providerKey", 2);
__decorateClass([
  Property({ name: "external_reaction_id", type: "text", nullable: true })
], MessageReaction.prototype, "externalReactionId", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], MessageReaction.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], MessageReaction.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], MessageReaction.prototype, "createdAt", 2);
MessageReaction = __decorateClass([
  Entity({ tableName: "message_reactions" }),
  Index({ name: "message_reactions_message_idx", properties: ["messageId"] }),
  Index({ name: "message_reactions_message_emoji_idx", properties: ["messageId", "emoji"] }),
  Index({
    name: "message_reactions_internal_actor_uq",
    expression: `create unique index "message_reactions_internal_actor_uq" on "message_reactions" ("tenant_id", "message_id", "emoji", "reacted_by_user_id") where "reacted_by_user_id" is not null`
  }),
  Index({
    name: "message_reactions_external_actor_uq",
    expression: `create unique index "message_reactions_external_actor_uq" on "message_reactions" ("tenant_id", "message_id", "emoji", "reacted_by_external_id") where "reacted_by_external_id" is not null`
  }),
  Check({
    name: "message_reactions_exactly_one_actor_chk",
    expression: `("reacted_by_user_id" is null) <> ("reacted_by_external_id" is null)`
  })
], MessageReaction);
OptionalProps;
let ChannelThreadToken = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], ChannelThreadToken.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], ChannelThreadToken.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], ChannelThreadToken.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "message_thread_id", type: "uuid" })
], ChannelThreadToken.prototype, "messageThreadId", 2);
__decorateClass([
  Property({ name: "token", type: "text" })
], ChannelThreadToken.prototype, "token", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], ChannelThreadToken.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "last_seen_at", type: Date, nullable: true })
], ChannelThreadToken.prototype, "lastSeenAt", 2);
ChannelThreadToken = __decorateClass([
  Entity({ tableName: "channel_thread_tokens" }),
  Unique({ name: "channel_thread_tokens_thread_uq", properties: ["tenantId", "messageThreadId"] }),
  Unique({ name: "channel_thread_tokens_token_uq", properties: ["tenantId", "token"] })
], ChannelThreadToken);
OptionalProps;
let ChannelIngestDeadLetter = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], ChannelIngestDeadLetter.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], ChannelIngestDeadLetter.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], ChannelIngestDeadLetter.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "channel_id", type: "uuid" })
], ChannelIngestDeadLetter.prototype, "channelId", 2);
__decorateClass([
  Property({ name: "provider_key", type: "text" })
], ChannelIngestDeadLetter.prototype, "providerKey", 2);
__decorateClass([
  Property({ name: "external_uid", type: "text", nullable: true })
], ChannelIngestDeadLetter.prototype, "externalUid", 2);
__decorateClass([
  Property({ name: "external_message_id", type: "text", nullable: true })
], ChannelIngestDeadLetter.prototype, "externalMessageId", 2);
__decorateClass([
  Property({ name: "error_class", type: "text" })
], ChannelIngestDeadLetter.prototype, "errorClass", 2);
__decorateClass([
  Property({ name: "error_message", type: "text" })
], ChannelIngestDeadLetter.prototype, "errorMessage", 2);
__decorateClass([
  Property({ name: "raw_body", type: "text", nullable: true })
], ChannelIngestDeadLetter.prototype, "rawBody", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], ChannelIngestDeadLetter.prototype, "createdAt", 2);
ChannelIngestDeadLetter = __decorateClass([
  Entity({ tableName: "channel_ingest_dead_letters" }),
  Index({ name: "channel_ingest_dead_letters_channel_idx", properties: ["channelId", "tenantId"] }),
  Index({ name: "channel_ingest_dead_letters_created_idx", properties: ["tenantId", "createdAt"] })
], ChannelIngestDeadLetter);
export {
  ChannelIngestDeadLetter,
  ChannelThreadMapping,
  ChannelThreadToken,
  CommunicationChannel,
  ExternalConversation,
  ExternalMessage,
  MessageChannelLink,
  MessageReaction
};
//# sourceMappingURL=entities.js.map
