import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
import { InboxSettings } from "./data/entities.js";
const setup = {
  defaultRoleFeatures: {
    superadmin: ["inbox_ops.*"],
    admin: [
      "inbox_ops.proposals.view",
      "inbox_ops.proposals.manage",
      "inbox_ops.settings.manage",
      "inbox_ops.log.view",
      "inbox_ops.replies.send"
    ],
    employee: [
      "inbox_ops.proposals.view",
      "inbox_ops.proposals.manage",
      "inbox_ops.replies.send"
    ]
  },
  async onTenantCreated({ em, tenantId, organizationId }) {
    const exists = await findOneWithDecryption(
      em,
      InboxSettings,
      { tenantId, organizationId, deletedAt: null },
      void 0,
      { tenantId, organizationId }
    );
    if (!exists) {
      const domain = process.env.INBOX_OPS_DOMAIN || "inbox.mercato.local";
      const slug = organizationId.slice(0, 8);
      const inboxAddress = `ops-${slug}@${domain}`;
      em.persist(em.create(InboxSettings, {
        tenantId,
        organizationId,
        inboxAddress,
        isActive: true
      }));
    }
    await em.flush();
  },
  async seedDefaults() {
  }
};
var setup_default = setup;
export {
  setup_default as default,
  setup
};
//# sourceMappingURL=setup.js.map
