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 { Check, Entity, Enum, Index, ManyToOne, PrimaryKey, Property, Unique } from "@mikro-orm/decorators/legacy";
const DOMAIN_PROVIDERS = ["traefik"];
const DOMAIN_STATUSES = [
  "pending",
  "verified",
  "active",
  "dns_failed",
  "tls_failed"
];
let CustomerUser = class {
  constructor() {
    this.failedLoginAttempts = 0;
    this.isActive = true;
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CustomerUser.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], CustomerUser.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid" })
], CustomerUser.prototype, "organizationId", 2);
__decorateClass([
  Property({ type: "text" })
], CustomerUser.prototype, "email", 2);
__decorateClass([
  Property({ name: "email_hash", type: "text" }),
  Index({ name: "customer_users_email_hash_idx" })
], CustomerUser.prototype, "emailHash", 2);
__decorateClass([
  Property({ name: "password_hash", type: "text", nullable: true })
], CustomerUser.prototype, "passwordHash", 2);
__decorateClass([
  Property({ name: "display_name", type: "text" })
], CustomerUser.prototype, "displayName", 2);
__decorateClass([
  Property({ name: "email_verified_at", type: Date, nullable: true })
], CustomerUser.prototype, "emailVerifiedAt", 2);
__decorateClass([
  Property({ name: "failed_login_attempts", type: "int", default: 0 })
], CustomerUser.prototype, "failedLoginAttempts", 2);
__decorateClass([
  Property({ name: "locked_until", type: Date, nullable: true })
], CustomerUser.prototype, "lockedUntil", 2);
__decorateClass([
  Property({ name: "last_login_at", type: Date, nullable: true })
], CustomerUser.prototype, "lastLoginAt", 2);
__decorateClass([
  Property({ name: "sessions_revoked_at", type: Date, nullable: true })
], CustomerUser.prototype, "sessionsRevokedAt", 2);
__decorateClass([
  Property({ name: "person_entity_id", type: "uuid", nullable: true }),
  Index({ name: "customer_users_person_entity_idx" })
], CustomerUser.prototype, "personEntityId", 2);
__decorateClass([
  Property({ name: "customer_entity_id", type: "uuid", nullable: true }),
  Index({ name: "customer_users_customer_entity_idx" })
], CustomerUser.prototype, "customerEntityId", 2);
__decorateClass([
  Property({ name: "is_active", type: "boolean", default: true })
], CustomerUser.prototype, "isActive", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CustomerUser.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date(), nullable: true })
], CustomerUser.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], CustomerUser.prototype, "deletedAt", 2);
CustomerUser = __decorateClass([
  Entity({ tableName: "customer_users" }),
  Unique({ properties: ["tenantId", "emailHash"], name: "customer_users_tenant_email_hash_uniq" })
], CustomerUser);
let CustomerRole = class {
  constructor() {
    this.isDefault = false;
    this.isSystem = false;
    this.customerAssignable = false;
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CustomerRole.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], CustomerRole.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid" })
], CustomerRole.prototype, "organizationId", 2);
__decorateClass([
  Property({ type: "text" })
], CustomerRole.prototype, "name", 2);
__decorateClass([
  Property({ type: "text" })
], CustomerRole.prototype, "slug", 2);
__decorateClass([
  Property({ type: "text", nullable: true })
], CustomerRole.prototype, "description", 2);
__decorateClass([
  Property({ name: "is_default", type: "boolean", default: false })
], CustomerRole.prototype, "isDefault", 2);
__decorateClass([
  Property({ name: "is_system", type: "boolean", default: false })
], CustomerRole.prototype, "isSystem", 2);
__decorateClass([
  Property({ name: "customer_assignable", type: "boolean", default: false })
], CustomerRole.prototype, "customerAssignable", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CustomerRole.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date(), nullable: true })
], CustomerRole.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], CustomerRole.prototype, "deletedAt", 2);
CustomerRole = __decorateClass([
  Entity({ tableName: "customer_roles" }),
  Unique({ properties: ["tenantId", "slug"], name: "customer_roles_tenant_slug_uniq" })
], CustomerRole);
let CustomerRoleAcl = class {
  constructor() {
    this.isPortalAdmin = false;
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CustomerRoleAcl.prototype, "id", 2);
__decorateClass([
  ManyToOne(() => CustomerRole)
], CustomerRoleAcl.prototype, "role", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], CustomerRoleAcl.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "features_json", type: "json", nullable: true })
], CustomerRoleAcl.prototype, "featuresJson", 2);
__decorateClass([
  Property({ name: "is_portal_admin", type: "boolean", default: false })
], CustomerRoleAcl.prototype, "isPortalAdmin", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CustomerRoleAcl.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date(), nullable: true })
], CustomerRoleAcl.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], CustomerRoleAcl.prototype, "deletedAt", 2);
CustomerRoleAcl = __decorateClass([
  Entity({ tableName: "customer_role_acls" }),
  Unique({ properties: ["role", "tenantId"], name: "customer_role_acls_role_tenant_uniq" })
], CustomerRoleAcl);
let CustomerUserRole = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CustomerUserRole.prototype, "id", 2);
__decorateClass([
  ManyToOne(() => CustomerUser)
], CustomerUserRole.prototype, "user", 2);
__decorateClass([
  ManyToOne(() => CustomerRole)
], CustomerUserRole.prototype, "role", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CustomerUserRole.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], CustomerUserRole.prototype, "deletedAt", 2);
CustomerUserRole = __decorateClass([
  Entity({ tableName: "customer_user_roles" }),
  Unique({ properties: ["user", "role"], name: "customer_user_roles_user_role_uniq" })
], CustomerUserRole);
let CustomerUserAcl = class {
  constructor() {
    this.isPortalAdmin = false;
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CustomerUserAcl.prototype, "id", 2);
__decorateClass([
  ManyToOne(() => CustomerUser)
], CustomerUserAcl.prototype, "user", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], CustomerUserAcl.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "features_json", type: "json", nullable: true })
], CustomerUserAcl.prototype, "featuresJson", 2);
__decorateClass([
  Property({ name: "is_portal_admin", type: "boolean", default: false })
], CustomerUserAcl.prototype, "isPortalAdmin", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CustomerUserAcl.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date(), nullable: true })
], CustomerUserAcl.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], CustomerUserAcl.prototype, "deletedAt", 2);
CustomerUserAcl = __decorateClass([
  Entity({ tableName: "customer_user_acls" }),
  Unique({ properties: ["user", "tenantId"], name: "customer_user_acls_user_tenant_uniq" })
], CustomerUserAcl);
let CustomerUserSession = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CustomerUserSession.prototype, "id", 2);
__decorateClass([
  ManyToOne(() => CustomerUser)
], CustomerUserSession.prototype, "user", 2);
__decorateClass([
  Property({ name: "token_hash", type: "text" })
], CustomerUserSession.prototype, "tokenHash", 2);
__decorateClass([
  Property({ name: "ip_address", type: "text", nullable: true })
], CustomerUserSession.prototype, "ipAddress", 2);
__decorateClass([
  Property({ name: "user_agent", type: "text", nullable: true })
], CustomerUserSession.prototype, "userAgent", 2);
__decorateClass([
  Property({ name: "expires_at", type: Date })
], CustomerUserSession.prototype, "expiresAt", 2);
__decorateClass([
  Property({ name: "last_used_at", type: Date, nullable: true })
], CustomerUserSession.prototype, "lastUsedAt", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CustomerUserSession.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], CustomerUserSession.prototype, "deletedAt", 2);
CustomerUserSession = __decorateClass([
  Entity({ tableName: "customer_user_sessions" }),
  Index({ properties: ["tokenHash"], name: "customer_user_sessions_token_hash_idx" })
], CustomerUserSession);
let CustomerUserEmailVerification = class {
  constructor() {
    this.purpose = "email_verification";
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CustomerUserEmailVerification.prototype, "id", 2);
__decorateClass([
  ManyToOne(() => CustomerUser)
], CustomerUserEmailVerification.prototype, "user", 2);
__decorateClass([
  Property({ type: "text" })
], CustomerUserEmailVerification.prototype, "token", 2);
__decorateClass([
  Property({ type: "text", default: "email_verification" })
], CustomerUserEmailVerification.prototype, "purpose", 2);
__decorateClass([
  Property({ name: "expires_at", type: Date })
], CustomerUserEmailVerification.prototype, "expiresAt", 2);
__decorateClass([
  Property({ name: "used_at", type: Date, nullable: true })
], CustomerUserEmailVerification.prototype, "usedAt", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CustomerUserEmailVerification.prototype, "createdAt", 2);
CustomerUserEmailVerification = __decorateClass([
  Entity({ tableName: "customer_user_email_verifications" }),
  Index({ properties: ["token"], name: "customer_user_email_verifications_token_idx" })
], CustomerUserEmailVerification);
let CustomerUserPasswordReset = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CustomerUserPasswordReset.prototype, "id", 2);
__decorateClass([
  ManyToOne(() => CustomerUser)
], CustomerUserPasswordReset.prototype, "user", 2);
__decorateClass([
  Property({ type: "text" })
], CustomerUserPasswordReset.prototype, "token", 2);
__decorateClass([
  Property({ name: "expires_at", type: Date })
], CustomerUserPasswordReset.prototype, "expiresAt", 2);
__decorateClass([
  Property({ name: "used_at", type: Date, nullable: true })
], CustomerUserPasswordReset.prototype, "usedAt", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CustomerUserPasswordReset.prototype, "createdAt", 2);
CustomerUserPasswordReset = __decorateClass([
  Entity({ tableName: "customer_user_password_resets" }),
  Index({ properties: ["token"], name: "customer_user_password_resets_token_idx" })
], CustomerUserPasswordReset);
let CustomerUserInvitation = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], CustomerUserInvitation.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], CustomerUserInvitation.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid" })
], CustomerUserInvitation.prototype, "organizationId", 2);
__decorateClass([
  Property({ type: "text" })
], CustomerUserInvitation.prototype, "email", 2);
__decorateClass([
  Property({ name: "email_hash", type: "text" })
], CustomerUserInvitation.prototype, "emailHash", 2);
__decorateClass([
  Property({ type: "text" })
], CustomerUserInvitation.prototype, "token", 2);
__decorateClass([
  Property({ name: "customer_entity_id", type: "uuid", nullable: true })
], CustomerUserInvitation.prototype, "customerEntityId", 2);
__decorateClass([
  Property({ name: "role_ids_json", type: "json", nullable: true })
], CustomerUserInvitation.prototype, "roleIdsJson", 2);
__decorateClass([
  Property({ name: "invited_by_user_id", type: "uuid", nullable: true })
], CustomerUserInvitation.prototype, "invitedByUserId", 2);
__decorateClass([
  Property({ name: "invited_by_customer_user_id", type: "uuid", nullable: true })
], CustomerUserInvitation.prototype, "invitedByCustomerUserId", 2);
__decorateClass([
  Property({ name: "display_name", type: "text", nullable: true })
], CustomerUserInvitation.prototype, "displayName", 2);
__decorateClass([
  Property({ name: "expires_at", type: Date })
], CustomerUserInvitation.prototype, "expiresAt", 2);
__decorateClass([
  Property({ name: "accepted_at", type: Date, nullable: true })
], CustomerUserInvitation.prototype, "acceptedAt", 2);
__decorateClass([
  Property({ name: "cancelled_at", type: Date, nullable: true })
], CustomerUserInvitation.prototype, "cancelledAt", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], CustomerUserInvitation.prototype, "createdAt", 2);
CustomerUserInvitation = __decorateClass([
  Entity({ tableName: "customer_user_invitations" }),
  Index({ properties: ["token"], name: "customer_user_invitations_token_idx" }),
  Index({ properties: ["tenantId", "emailHash"], name: "customer_user_invitations_tenant_email_hash_idx" })
], CustomerUserInvitation);
let DomainMapping = class {
  constructor() {
    this.provider = "traefik";
    this.status = "pending";
    this.tlsRetryCount = 0;
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], DomainMapping.prototype, "id", 2);
__decorateClass([
  Property({ type: "text" })
], DomainMapping.prototype, "hostname", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], DomainMapping.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid" })
], DomainMapping.prototype, "organizationId", 2);
__decorateClass([
  ManyToOne(() => DomainMapping, { fieldName: "replaces_domain_id", nullable: true })
], DomainMapping.prototype, "replacesDomain", 2);
__decorateClass([
  Enum({ items: () => DOMAIN_PROVIDERS, type: "text", name: "provider" })
], DomainMapping.prototype, "provider", 2);
__decorateClass([
  Enum({ items: () => DOMAIN_STATUSES, type: "text", name: "status" })
], DomainMapping.prototype, "status", 2);
__decorateClass([
  Property({ name: "verified_at", type: Date, nullable: true })
], DomainMapping.prototype, "verifiedAt", 2);
__decorateClass([
  Property({ name: "last_dns_check_at", type: Date, nullable: true })
], DomainMapping.prototype, "lastDnsCheckAt", 2);
__decorateClass([
  Property({ name: "dns_failure_reason", type: "text", nullable: true, length: 500 })
], DomainMapping.prototype, "dnsFailureReason", 2);
__decorateClass([
  Property({ name: "tls_failure_reason", type: "text", nullable: true, length: 500 })
], DomainMapping.prototype, "tlsFailureReason", 2);
__decorateClass([
  Property({ name: "tls_retry_count", type: "int", default: 0 })
], DomainMapping.prototype, "tlsRetryCount", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], DomainMapping.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date(), nullable: true })
], DomainMapping.prototype, "updatedAt", 2);
DomainMapping = __decorateClass([
  Entity({ tableName: "domain_mappings" }),
  Unique({ properties: ["hostname"], name: "domain_mappings_hostname_unique" }),
  Index({ properties: ["organizationId"], name: "domain_mappings_organization_id_idx" }),
  Index({ properties: ["tenantId"], name: "domain_mappings_tenant_id_idx" }),
  Unique({
    name: "domain_mappings_replaces_domain_id_unique",
    expression: `create unique index "domain_mappings_replaces_domain_id_unique" on "domain_mappings" ("replaces_domain_id") where "replaces_domain_id" is not null`
  }),
  Index({
    name: "domain_mappings_pending_verification_idx",
    expression: `create index "domain_mappings_pending_verification_idx" on "domain_mappings" ("status", "last_dns_check_at") where "status" in ('pending', 'dns_failed')`
  }),
  Index({
    name: "domain_mappings_pending_tls_idx",
    expression: `create index "domain_mappings_pending_tls_idx" on "domain_mappings" ("status", "updated_at") where "status" in ('verified', 'tls_failed')`
  }),
  Check({
    name: "domain_mappings_hostname_normalized_chk",
    expression: `"hostname" = lower("hostname") and "hostname" not like '%.'`
  })
], DomainMapping);
export {
  CustomerRole,
  CustomerRoleAcl,
  CustomerUser,
  CustomerUserAcl,
  CustomerUserEmailVerification,
  CustomerUserInvitation,
  CustomerUserPasswordReset,
  CustomerUserRole,
  CustomerUserSession,
  DOMAIN_PROVIDERS,
  DOMAIN_STATUSES,
  DomainMapping
};
//# sourceMappingURL=entities.js.map
