import type { CommunityPostRecord } from "@/features/community/communityRecord";

/** Whether the «للتواصل» button belongs on this post for this reader (PDF p.26). */
export function canContactPostAuthor(
  post: Pick<CommunityPostRecord, "proposing_idea" | "is_creator" | "user">,
  viewerId?: number | string | null
): boolean {
  if (!post.proposing_idea || post.is_creator) return false;
  /* `contact-creator` answers 422 on your own idea; `is_creator` is the flag,
     the author id the fallback when the flag is missing. */
  return !(viewerId != null && post.user?.id != null && String(post.user.id) === String(viewerId));
}
