export function shouldPersistRemoteOverview(overview: unknown): boolean {
  if (!Array.isArray(overview) || overview.length === 0) return false;
  return overview.some(hasFrontendTreeSignal);
}

function hasFrontendTreeSignal(product: unknown): boolean {
  if (!isRecord(product)) return false;
  const projects = Array.isArray(product.projects) ? product.projects : [];
  const versions = Array.isArray(product.versions) ? product.versions : [];
  return projects.some(isFrontendProject) || versions.some(isFrontendVersion);
}

function isFrontendProject(project: unknown): boolean {
  return (
    isRecord(project) &&
    typeof project.id === 'string' &&
    project.id.startsWith('proj-') &&
    typeof project.name === 'string'
  );
}

function isFrontendVersion(version: unknown): boolean {
  if (!isRecord(version) || typeof version.id !== 'string' || typeof version.name !== 'string') return false;
  return (
    version.id.startsWith('ver-') ||
    typeof version.status === 'string' ||
    typeof version.expectedReleaseDate === 'string' ||
    Array.isArray(version.members) ||
    typeof version.priority === 'string'
  );
}

function isRecord(value: unknown): value is Record<string, unknown> {
  return typeof value === 'object' && value !== null;
}
