import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
import { seedPlannerAvailabilityRuleSetDefaults, seedPlannerUnavailabilityReasons } from "./lib/seeds.js";
function parseArgs(rest) {
  const args = {};
  for (let i = 0; i < rest.length; i += 1) {
    const part = rest[i];
    if (!part) continue;
    if (part.startsWith("--")) {
      const [rawKey, rawValue] = part.slice(2).split("=");
      if (rawValue !== void 0) args[rawKey] = rawValue;
      else if (rest[i + 1] && !rest[i + 1].startsWith("--")) {
        args[rawKey] = rest[i + 1];
        i += 1;
      }
    }
  }
  return args;
}
const seedAvailabilityRuleSetsCommand = {
  command: "seed-availability-rulesets",
  async run(rest) {
    const args = parseArgs(rest);
    const tenantId = String(args.tenantId ?? args.tenant ?? "");
    const organizationId = String(args.organizationId ?? args.org ?? args.orgId ?? "");
    if (!tenantId || !organizationId) {
      console.error("Usage: mercato planner seed-availability-rulesets --tenant <tenantId> --org <organizationId>");
      return;
    }
    const container = await createRequestContainer();
    const scope = { tenantId, organizationId };
    try {
      const em = container.resolve("em");
      await em.transactional(async (tem) => {
        await seedPlannerAvailabilityRuleSetDefaults(tem, scope);
      });
      console.log("\u{1F5D3}\uFE0F  Planner availability rule sets seeded for organization", organizationId);
    } finally {
      const disposable = container;
      if (typeof disposable.dispose === "function") {
        await disposable.dispose();
      }
    }
  }
};
const seedUnavailabilityReasonsCommand = {
  command: "seed-unavailability-reasons",
  async run(rest) {
    const args = parseArgs(rest);
    const tenantId = String(args.tenantId ?? args.tenant ?? "");
    const organizationId = String(args.organizationId ?? args.org ?? args.orgId ?? "");
    if (!tenantId || !organizationId) {
      console.error("Usage: mercato planner seed-unavailability-reasons --tenant <tenantId> --org <organizationId>");
      return;
    }
    const container = await createRequestContainer();
    const scope = { tenantId, organizationId };
    try {
      const em = container.resolve("em");
      await em.transactional(async (tem) => {
        await seedPlannerUnavailabilityReasons(tem, scope);
      });
      console.log("\u{1F5D3}\uFE0F  Planner unavailability reasons seeded for organization", organizationId);
    } finally {
      const disposable = container;
      if (typeof disposable.dispose === "function") {
        await disposable.dispose();
      }
    }
  }
};
var cli_default = [seedAvailabilityRuleSetsCommand, seedUnavailabilityReasonsCommand];
export {
  cli_default as default
};
//# sourceMappingURL=cli.js.map
