import type { User } from '../../../../shared-kernel';
import type { DirectMessage, DirectMessageParticipant } from '../../../../shared-kernel';

export type DirectMessageConversationKind = 'direct' | 'group';

export type {
  DirectMessage,
  DirectMessageEventPayload,
  DirectMessageMutationEventPayload,
  DirectMessageParticipant,
  DirectMessageSyncEventPayload,
  DirectMessageSyncRequestEventPayload,
  DirectMessageStatus,
  DirectMessageStatusEventPayload,
  DirectMessageTypingEventPayload
} from '../../../../shared-kernel';

export interface DirectMessageConversation {
  id: string;
  kind?: DirectMessageConversationKind;
  title?: string;
  participants: string[];
  participantProfiles: Record<string, DirectMessageParticipant>;
  messages: DirectMessage[];
  lastMessageAt: number;
  unreadCount: number;
}

export interface Friend {
  userId: string;
  addedAt: number;
}

export function toDirectMessageParticipant(user: User): DirectMessageParticipant {
  return {
    userId: user.oderId || user.id,
    username: user.username,
    displayName: user.displayName || user.username,
    description: user.description,
    avatarUrl: user.avatarUrl,
    avatarHash: user.avatarHash,
    avatarMime: user.avatarMime,
    avatarUpdatedAt: user.avatarUpdatedAt,
    profileUpdatedAt: user.profileUpdatedAt
  };
}
