import { renderAgentRunManagedRepositoryReconcilerFragment } from "./agentrun-managed-repository-reconciler";
import { renderPacAdmissionDesiredFragment } from "./platform-infra-pac-provenance";
import { renderPacConsumerRbacDesiredFragment } from "./platform-infra-pac-consumer-rbac";

export function renderPlatformInfraGiteaDesiredFragments(targetId: string): string {
  return [
    renderPacConsumerRbacDesiredFragment(targetId),
    renderPacAdmissionDesiredFragment(targetId),
    renderAgentRunManagedRepositoryReconcilerFragment(targetId),
  ].map(normalizeFragment).filter((item) => item.length > 0).join("\n---\n");
}

function normalizeFragment(value: string): string {
  return value.trim().replace(/^(?:---\s*)+|(?:\s*---)+$/gu, "");
}
