import type { MessageWithMeta } from '@/contexts';

/** Returns the user UID for a message, if the sender is a human user */
export function getSenderUserUid(message: MessageWithMeta): string | undefined {
  return message.sender_id ?? undefined;
}

/** Returns the model ID for AI messages */
export function getSenderModelId(message: MessageWithMeta): string | undefined {
  if (message.sender_type === 'ai' && message.sender_id) {
    return message.sender_id;
  }
  return undefined;
}

/** Display name for a message sender */
export function getSenderDisplayName(message: MessageWithMeta): string {
  if (message.sender_type === 'ai') {
    if (message.display_name) return message.display_name;
    return 'AI';
  }
  if (message.display_name) return message.display_name;
  if (message.sender_type === 'system') return 'System';
  return message.sender_type;
}

/** Avatar URL from a MessageWithMeta.
 *  Callers should pass members to resolve the avatar.
 *  This helper returns undefined for now — avatar resolution is done in components
 *  using members.find() for consistency with the rest of the codebase.
 */
export function getAvatarFromUiMessage(_message: MessageWithMeta): string | undefined {
  return undefined;
}

/** Whether the sender is a human user */
export function isUserSender(message: MessageWithMeta): boolean {
  return ['member', 'admin', 'owner', 'guest'].includes(message.sender_type);
}
