import type { ProfileBrief } from '../friends/index.js';
import type { ConversationType, MemberRole } from '../supabase/types.js';

export interface ConversationMember {
  userId: string;
  role: MemberRole;
  accepted: boolean;
  profile: ProfileBrief | null;
}

export interface ConversationSummary {
  id: string;
  type: ConversationType;
  name: string | null;
  avatarUrl: string | null;
  createdAt: string;
  // For DMs: the OTHER member's profile. null for groups.
  peer: ProfileBrief | null;
  // Caller's accepted flag on their own membership row (DM-request flow).
  acceptedByMe: boolean;
  // Caller's role inside this conversation.
  myRole: MemberRole;
  members: ConversationMember[];
  // Latest message timestamp (server can't see content, only metadata).
  lastMessageAt: string | null;
  // Caller's per-member preferences.
  archived: boolean;
  // ISO timestamp. null = not muted. Past timestamp = expired mute (treat as
  // not muted — the server row is kept for history until the next toggle).
  mutedUntil: string | null;
}

export interface ChatMessage {
  id: string;
  conversationId: string;
  senderId: string;
  senderDeviceId: string | null;
  replyToId: string | null;
  editedAt: string | null;
  deletedAt: string | null;
  createdAt: string;
}

export interface DecryptedMessage extends ChatMessage {
  // null when decryption failed (envelope missing for our device, key gone, etc.).
  plaintext: string | null;
}
