import type { LifecycleEvidence } from "./types.js";

export type LifecycleViolation = {
  rule: string;
  fact: string;
  details?: unknown;
};

export function detectLifecycleViolations(lifecycle: LifecycleEvidence): LifecycleViolation[] {
  const violations: LifecycleViolation[] = [];

  for (const resource of lifecycle.ownedResources) {
    if (!resource.released) {
      violations.push({
        rule: "UNI-051",
        fact: `Owned resource ${resource.kind}:${resource.id} was not released`,
        details: { resource },
      });
    }
  }

  if (lifecycle.postTerminalEvents.length > 0) {
    violations.push({
      rule: "UNI-061",
      fact: "Post-terminal event observed after terminal state",
      details: { postTerminalEvents: lifecycle.postTerminalEvents },
    });
  }

  return violations;
}
