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 { Entity, Index, PrimaryKey, Property, Unique } from "@mikro-orm/decorators/legacy";
let EntityIndexRow = class {
  constructor() {
    this.indexVersion = 1;
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], EntityIndexRow.prototype, "id", 2);
__decorateClass([
  Property({ name: "entity_type", type: "text" }),
  Index({ name: "entity_indexes_type_idx" })
], EntityIndexRow.prototype, "entityType", 2);
__decorateClass([
  Property({ name: "entity_id", type: "text" }),
  Index({ name: "entity_indexes_entity_idx" })
], EntityIndexRow.prototype, "entityId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true }),
  Index({ name: "entity_indexes_org_idx" })
], EntityIndexRow.prototype, "organizationId", 2);
__decorateClass([
  Property({
    name: "organization_id_coalesced",
    type: "uuid",
    generated: (cols) => `(coalesce(${cols.organizationId}, '00000000-0000-0000-0000-000000000000'::uuid)) stored`,
    hidden: true
  })
], EntityIndexRow.prototype, "organizationIdCoalesced", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid", nullable: true })
], EntityIndexRow.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "doc", type: "json" })
], EntityIndexRow.prototype, "doc", 2);
__decorateClass([
  Property({ name: "embedding", type: "json", nullable: true })
], EntityIndexRow.prototype, "embedding", 2);
__decorateClass([
  Property({ name: "index_version", type: "int", default: 1 })
], EntityIndexRow.prototype, "indexVersion", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], EntityIndexRow.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], EntityIndexRow.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], EntityIndexRow.prototype, "deletedAt", 2);
EntityIndexRow = __decorateClass([
  Entity({ tableName: "entity_indexes" }),
  Index({
    name: "entity_indexes_customer_entity_doc_idx",
    expression: `create index "entity_indexes_customer_entity_doc_idx" on "entity_indexes" ("entity_id", "organization_id", "tenant_id") include ("doc") where deleted_at is null and entity_type = 'customers:customer_entity' and organization_id is not null and tenant_id is not null`
  }),
  Index({
    name: "entity_indexes_customer_person_profile_doc_idx",
    expression: `create index "entity_indexes_customer_person_profile_doc_idx" on "entity_indexes" ("entity_id", "organization_id", "tenant_id") include ("doc") where deleted_at is null and entity_type = 'customers:customer_person_profile' and organization_id is not null and tenant_id is not null`
  }),
  Index({
    name: "entity_indexes_customer_company_profile_doc_idx",
    expression: `create index "entity_indexes_customer_company_profile_doc_idx" on "entity_indexes" ("entity_id", "organization_id", "tenant_id") include ("doc") where deleted_at is null and entity_type = 'customers:customer_company_profile' and organization_id is not null and tenant_id is not null`
  }),
  Index({
    name: "entity_indexes_customer_entity_tenant_doc_idx",
    expression: `create index "entity_indexes_customer_entity_tenant_doc_idx" on "entity_indexes" ("tenant_id", "entity_id") include ("doc") where deleted_at is null and entity_type = 'customers:customer_entity' and organization_id is null and tenant_id is not null`
  }),
  Index({
    name: "entity_indexes_customer_person_profile_tenant_doc_idx",
    expression: `create index "entity_indexes_customer_person_profile_tenant_doc_idx" on "entity_indexes" ("tenant_id", "entity_id") include ("doc") where deleted_at is null and entity_type = 'customers:customer_person_profile' and organization_id is null and tenant_id is not null`
  }),
  Index({
    name: "entity_indexes_customer_company_profile_tenant_doc_idx",
    expression: `create index "entity_indexes_customer_company_profile_tenant_doc_idx" on "entity_indexes" ("tenant_id", "entity_id") include ("doc") where deleted_at is null and entity_type = 'customers:customer_company_profile' and organization_id is null and tenant_id is not null`
  }),
  Index({ name: "entity_indexes_type_tenant_idx", properties: ["entityType", "tenantId"] }),
  Unique({
    name: "entity_indexes_type_entity_org_coalesced_unique",
    properties: ["entityType", "entityId", "organizationIdCoalesced"]
  })
], EntityIndexRow);
let EntityIndexJob = class {
  constructor() {
    this.startedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], EntityIndexJob.prototype, "id", 2);
__decorateClass([
  Property({ name: "entity_type", type: "text" }),
  Index({ name: "entity_index_jobs_type_idx" })
], EntityIndexJob.prototype, "entityType", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true }),
  Index({ name: "entity_index_jobs_org_idx" })
], EntityIndexJob.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid", nullable: true })
], EntityIndexJob.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "partition_index", type: "int", nullable: true })
], EntityIndexJob.prototype, "partitionIndex", 2);
__decorateClass([
  Property({ name: "partition_count", type: "int", nullable: true })
], EntityIndexJob.prototype, "partitionCount", 2);
__decorateClass([
  Property({ name: "processed_count", type: "int", nullable: true })
], EntityIndexJob.prototype, "processedCount", 2);
__decorateClass([
  Property({ name: "total_count", type: "int", nullable: true })
], EntityIndexJob.prototype, "totalCount", 2);
__decorateClass([
  Property({ name: "heartbeat_at", type: Date, nullable: true })
], EntityIndexJob.prototype, "heartbeatAt", 2);
__decorateClass([
  Property({ name: "status", type: "text" })
], EntityIndexJob.prototype, "status", 2);
__decorateClass([
  Property({ name: "started_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], EntityIndexJob.prototype, "startedAt", 2);
__decorateClass([
  Property({ name: "finished_at", type: Date, nullable: true })
], EntityIndexJob.prototype, "finishedAt", 2);
EntityIndexJob = __decorateClass([
  Entity({ tableName: "entity_index_jobs" }),
  Unique({
    name: "entity_index_jobs_scope_unique",
    expression: `create unique index "entity_index_jobs_scope_unique" on "entity_index_jobs" ("entity_type", coalesce("organization_id", '00000000-0000-0000-0000-000000000000'::uuid), coalesce("tenant_id", '00000000-0000-0000-0000-000000000000'::uuid), coalesce("partition_index", -1), coalesce("partition_count", -1))`
  })
], EntityIndexJob);
let EntityIndexCoverage = class {
  constructor() {
    this.withDeleted = false;
    this.baseCount = 0;
    this.indexedCount = 0;
    this.vectorIndexedCount = 0;
    this.refreshedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], EntityIndexCoverage.prototype, "id", 2);
__decorateClass([
  Property({ name: "entity_type", type: "text" })
], EntityIndexCoverage.prototype, "entityType", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid", nullable: true })
], EntityIndexCoverage.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], EntityIndexCoverage.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "with_deleted", type: "boolean", default: false })
], EntityIndexCoverage.prototype, "withDeleted", 2);
__decorateClass([
  Property({ name: "base_count", type: "int", unsigned: true, default: 0 })
], EntityIndexCoverage.prototype, "baseCount", 2);
__decorateClass([
  Property({ name: "indexed_count", type: "int", unsigned: true, default: 0 })
], EntityIndexCoverage.prototype, "indexedCount", 2);
__decorateClass([
  Property({ name: "vector_indexed_count", type: "int", unsigned: true, default: 0 })
], EntityIndexCoverage.prototype, "vectorIndexedCount", 2);
__decorateClass([
  Property({ name: "refreshed_at", type: Date, onCreate: () => /* @__PURE__ */ new Date(), onUpdate: () => /* @__PURE__ */ new Date() })
], EntityIndexCoverage.prototype, "refreshedAt", 2);
EntityIndexCoverage = __decorateClass([
  Entity({ tableName: "entity_index_coverage" }),
  Unique({
    name: "entity_index_coverage_scope_idx",
    properties: ["entityType", "tenantId", "organizationId", "withDeleted"]
  })
], EntityIndexCoverage);
let IndexerErrorLog = class {
  constructor() {
    this.occurredAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], IndexerErrorLog.prototype, "id", 2);
__decorateClass([
  Property({ name: "source", type: "text" })
], IndexerErrorLog.prototype, "source", 2);
__decorateClass([
  Property({ name: "handler", type: "text" })
], IndexerErrorLog.prototype, "handler", 2);
__decorateClass([
  Property({ name: "entity_type", type: "text", nullable: true })
], IndexerErrorLog.prototype, "entityType", 2);
__decorateClass([
  Property({ name: "record_id", type: "text", nullable: true })
], IndexerErrorLog.prototype, "recordId", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid", nullable: true })
], IndexerErrorLog.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], IndexerErrorLog.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "payload", type: "json", nullable: true })
], IndexerErrorLog.prototype, "payload", 2);
__decorateClass([
  Property({ name: "message", type: "text" })
], IndexerErrorLog.prototype, "message", 2);
__decorateClass([
  Property({ name: "stack", type: "text", nullable: true })
], IndexerErrorLog.prototype, "stack", 2);
__decorateClass([
  Property({ name: "occurred_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], IndexerErrorLog.prototype, "occurredAt", 2);
IndexerErrorLog = __decorateClass([
  Entity({ tableName: "indexer_error_logs" }),
  Index({ name: "indexer_error_logs_source_idx", properties: ["source"] }),
  Index({ name: "indexer_error_logs_occurred_idx", properties: ["occurredAt"] })
], IndexerErrorLog);
let IndexerStatusLog = class {
  constructor() {
    this.level = "info";
    this.occurredAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], IndexerStatusLog.prototype, "id", 2);
__decorateClass([
  Property({ name: "source", type: "text" })
], IndexerStatusLog.prototype, "source", 2);
__decorateClass([
  Property({ name: "handler", type: "text" })
], IndexerStatusLog.prototype, "handler", 2);
__decorateClass([
  Property({ name: "level", type: "text" })
], IndexerStatusLog.prototype, "level", 2);
__decorateClass([
  Property({ name: "entity_type", type: "text", nullable: true })
], IndexerStatusLog.prototype, "entityType", 2);
__decorateClass([
  Property({ name: "record_id", type: "text", nullable: true })
], IndexerStatusLog.prototype, "recordId", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid", nullable: true })
], IndexerStatusLog.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], IndexerStatusLog.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "message", type: "text" })
], IndexerStatusLog.prototype, "message", 2);
__decorateClass([
  Property({ name: "details", type: "json", nullable: true })
], IndexerStatusLog.prototype, "details", 2);
__decorateClass([
  Property({ name: "occurred_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], IndexerStatusLog.prototype, "occurredAt", 2);
IndexerStatusLog = __decorateClass([
  Entity({ tableName: "indexer_status_logs" }),
  Index({ name: "indexer_status_logs_source_idx", properties: ["source"] }),
  Index({ name: "indexer_status_logs_occurred_idx", properties: ["occurredAt"] })
], IndexerStatusLog);
let SearchToken = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], SearchToken.prototype, "id", 2);
__decorateClass([
  Property({ name: "entity_type", type: "text" })
], SearchToken.prototype, "entityType", 2);
__decorateClass([
  Property({ name: "entity_id", type: "text" })
], SearchToken.prototype, "entityId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], SearchToken.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid", nullable: true })
], SearchToken.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "field", type: "text" })
], SearchToken.prototype, "field", 2);
__decorateClass([
  Property({ name: "token_hash", type: "text" })
], SearchToken.prototype, "tokenHash", 2);
__decorateClass([
  Property({ name: "token", type: "text", nullable: true })
], SearchToken.prototype, "token", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], SearchToken.prototype, "createdAt", 2);
SearchToken = __decorateClass([
  Entity({ tableName: "search_tokens" }),
  Index({ name: "search_tokens_lookup_idx", properties: ["entityType", "field", "tokenHash", "tenantId", "organizationId"] }),
  Index({ name: "search_tokens_entity_idx", properties: ["entityType", "entityId"] }),
  Index({ name: "search_tokens_tenant_token_hash_idx", properties: ["tenantId", "tokenHash"] })
], SearchToken);
export {
  EntityIndexCoverage,
  EntityIndexJob,
  EntityIndexRow,
  IndexerErrorLog,
  IndexerStatusLog,
  SearchToken
};
//# sourceMappingURL=entities.js.map
