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 { Entity, Index, ManyToOne, PrimaryKey, Property, Unique } from "@mikro-orm/decorators/legacy";
OptionalProps;
let BusinessRule = class {
  constructor() {
    this.enabled = true;
    this.priority = 100;
    this.version = 1;
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], BusinessRule.prototype, "id", 2);
__decorateClass([
  Property({ name: "rule_id", type: "varchar", length: 50 })
], BusinessRule.prototype, "ruleId", 2);
__decorateClass([
  Property({ name: "rule_name", type: "varchar", length: 200 })
], BusinessRule.prototype, "ruleName", 2);
__decorateClass([
  Property({ name: "description", type: "text", nullable: true })
], BusinessRule.prototype, "description", 2);
__decorateClass([
  Property({ name: "rule_type", type: "varchar", length: 20 })
], BusinessRule.prototype, "ruleType", 2);
__decorateClass([
  Property({ name: "rule_category", type: "varchar", length: 50, nullable: true })
], BusinessRule.prototype, "ruleCategory", 2);
__decorateClass([
  Property({ name: "entity_type", type: "varchar", length: 50 })
], BusinessRule.prototype, "entityType", 2);
__decorateClass([
  Property({ name: "event_type", type: "varchar", length: 50, nullable: true })
], BusinessRule.prototype, "eventType", 2);
__decorateClass([
  Property({ name: "condition_expression", type: "jsonb", nullable: true })
], BusinessRule.prototype, "conditionExpression", 2);
__decorateClass([
  Property({ name: "success_actions", type: "jsonb", nullable: true })
], BusinessRule.prototype, "successActions", 2);
__decorateClass([
  Property({ name: "failure_actions", type: "jsonb", nullable: true })
], BusinessRule.prototype, "failureActions", 2);
__decorateClass([
  Property({ name: "enabled", type: "boolean", default: true })
], BusinessRule.prototype, "enabled", 2);
__decorateClass([
  Property({ name: "priority", type: "integer", default: 100 })
], BusinessRule.prototype, "priority", 2);
__decorateClass([
  Property({ name: "version", type: "integer", default: 1 })
], BusinessRule.prototype, "version", 2);
__decorateClass([
  Property({ name: "effective_from", type: Date, nullable: true })
], BusinessRule.prototype, "effectiveFrom", 2);
__decorateClass([
  Property({ name: "effective_to", type: Date, nullable: true })
], BusinessRule.prototype, "effectiveTo", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], BusinessRule.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid" })
], BusinessRule.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "created_by", type: "varchar", length: 50, nullable: true })
], BusinessRule.prototype, "createdBy", 2);
__decorateClass([
  Property({ name: "updated_by", type: "varchar", length: 50, nullable: true })
], BusinessRule.prototype, "updatedBy", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], BusinessRule.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], BusinessRule.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], BusinessRule.prototype, "deletedAt", 2);
BusinessRule = __decorateClass([
  Entity({ tableName: "business_rules" }),
  Unique({ properties: ["ruleId", "tenantId"] }),
  Index({ name: "business_rules_entity_event_idx", properties: ["entityType", "eventType", "enabled"] }),
  Index({ name: "business_rules_tenant_org_idx", properties: ["tenantId", "organizationId"] }),
  Index({ name: "business_rules_type_enabled_idx", properties: ["ruleType", "enabled", "priority"] })
], BusinessRule);
OptionalProps;
let RuleExecutionLog = class {
  constructor() {
    this.executedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "bigint", autoincrement: true })
], RuleExecutionLog.prototype, "id", 2);
__decorateClass([
  ManyToOne(() => BusinessRule, { fieldName: "rule_id", nullable: false })
], RuleExecutionLog.prototype, "rule", 2);
__decorateClass([
  Property({ name: "entity_id", type: "varchar", length: 255 })
], RuleExecutionLog.prototype, "entityId", 2);
__decorateClass([
  Property({ name: "entity_type", type: "varchar", length: 50 })
], RuleExecutionLog.prototype, "entityType", 2);
__decorateClass([
  Property({ name: "execution_result", type: "varchar", length: 20 })
], RuleExecutionLog.prototype, "executionResult", 2);
__decorateClass([
  Property({ name: "input_context", type: "jsonb", nullable: true })
], RuleExecutionLog.prototype, "inputContext", 2);
__decorateClass([
  Property({ name: "output_context", type: "jsonb", nullable: true })
], RuleExecutionLog.prototype, "outputContext", 2);
__decorateClass([
  Property({ name: "error_message", type: "text", nullable: true })
], RuleExecutionLog.prototype, "errorMessage", 2);
__decorateClass([
  Property({ name: "execution_time_ms", type: "integer" })
], RuleExecutionLog.prototype, "executionTimeMs", 2);
__decorateClass([
  Property({ name: "executed_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], RuleExecutionLog.prototype, "executedAt", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], RuleExecutionLog.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], RuleExecutionLog.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "executed_by", type: "varchar", length: 50, nullable: true })
], RuleExecutionLog.prototype, "executedBy", 2);
RuleExecutionLog = __decorateClass([
  Entity({ tableName: "rule_execution_logs" }),
  Index({ name: "rule_execution_logs_rule_idx", properties: ["rule"] }),
  Index({ name: "rule_execution_logs_entity_idx", properties: ["entityType", "entityId"] }),
  Index({ name: "rule_execution_logs_result_idx", properties: ["executionResult", "executedAt"] }),
  Index({ name: "rule_execution_logs_tenant_org_idx", properties: ["tenantId", "organizationId"] })
], RuleExecutionLog);
OptionalProps;
let RuleSet = class {
  constructor() {
    this.enabled = true;
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], RuleSet.prototype, "id", 2);
__decorateClass([
  Property({ name: "set_id", type: "varchar", length: 50 })
], RuleSet.prototype, "setId", 2);
__decorateClass([
  Property({ name: "set_name", type: "varchar", length: 200 })
], RuleSet.prototype, "setName", 2);
__decorateClass([
  Property({ name: "description", type: "text", nullable: true })
], RuleSet.prototype, "description", 2);
__decorateClass([
  Property({ name: "enabled", type: "boolean", default: true })
], RuleSet.prototype, "enabled", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], RuleSet.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid" })
], RuleSet.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "created_by", type: "varchar", length: 50, nullable: true })
], RuleSet.prototype, "createdBy", 2);
__decorateClass([
  Property({ name: "updated_by", type: "varchar", length: 50, nullable: true })
], RuleSet.prototype, "updatedBy", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], RuleSet.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], RuleSet.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], RuleSet.prototype, "deletedAt", 2);
RuleSet = __decorateClass([
  Entity({ tableName: "rule_sets" }),
  Unique({ properties: ["setId", "tenantId"] }),
  Index({ name: "rule_sets_tenant_org_idx", properties: ["tenantId", "organizationId"] }),
  Index({ name: "rule_sets_enabled_idx", properties: ["enabled"] })
], RuleSet);
OptionalProps;
let RuleSetMember = class {
  constructor() {
    this.sequence = 0;
    this.enabled = true;
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], RuleSetMember.prototype, "id", 2);
__decorateClass([
  ManyToOne(() => RuleSet, { fieldName: "rule_set_id", nullable: false })
], RuleSetMember.prototype, "ruleSet", 2);
__decorateClass([
  ManyToOne(() => BusinessRule, { fieldName: "rule_id", nullable: false })
], RuleSetMember.prototype, "rule", 2);
__decorateClass([
  Property({ name: "sequence", type: "integer", default: 0 })
], RuleSetMember.prototype, "sequence", 2);
__decorateClass([
  Property({ name: "enabled", type: "boolean", default: true })
], RuleSetMember.prototype, "enabled", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], RuleSetMember.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid" })
], RuleSetMember.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], RuleSetMember.prototype, "createdAt", 2);
RuleSetMember = __decorateClass([
  Entity({ tableName: "rule_set_members" }),
  Unique({ properties: ["ruleSet", "rule"] }),
  Index({ name: "rule_set_members_set_idx", properties: ["ruleSet", "sequence"] }),
  Index({ name: "rule_set_members_rule_idx", properties: ["rule"] }),
  Index({ name: "rule_set_members_tenant_org_idx", properties: ["tenantId", "organizationId"] })
], RuleSetMember);
export {
  BusinessRule,
  RuleExecutionLog,
  RuleSet,
  RuleSetMember
};
//# sourceMappingURL=entities.js.map
