import type { PostingContextData } from "@/types/workflow";
import type { ProjectSchedule } from "@/lib/project/defaults";

/** True when the post sequence can drive generation. */
export function hasUsablePostingContext(context: PostingContextData | undefined | null): boolean {
  if (!context) return false;
  if (context.saved) return true;
  // Allow generation when sequence posts already have preview content.
  const posts = Array.isArray(context.posts) ? context.posts : [];
  return posts.length > 0 && posts.some((p) => Boolean(p.content?.trim()));
}

/**
 * True when Smart Schedule was saved (saved flag or scheduleSeed from Save Schedule).
 * Default postsPerDay alone is NOT enough — that is always present in defaults.
 */
export function hasUsableSchedule(schedule: ProjectSchedule | undefined | null): boolean {
  if (!schedule) return false;
  if (schedule.saved) return true;
  return typeof schedule.scheduleSeed === "number";
}
