import { Model } from '@nozbe/watermelondb';
import { field, relation } from '@nozbe/watermelondb/decorators';
import Chat from './Chat';

export default class Message extends Model {
  static table = 'messages';

  static associations = {
    chats: { type: 'belongs_to' as const, key: 'chat_key' }
  };

  @field('chat_key') chatKey!: string;

  @field('composite_id') compositeId!: string;
  @field('message_id') messageId!: number;
  @field('is_group') isGroup!: boolean;
  @relation('chats', 'chat_key') chat!: Chat;

  @field('sender_id') senderId!: number;
  @field('recipient_id') recipientId!: number;
  @field('text') text?: string;

  @field('sent_at') sentAt!: string;
  @field('received_at') receivedAt?: string | null;
  @field('read_at') readAt?: string | null;
  @field('status') status!: number;

  @field('reactions') reactions?: string | null;
  @field('edits') edits?: string | null;
  @field('attachment') attachment?: string | null;
  @field('reply_to_id') replyToId?: number | null;
  @field('reply_to') replyTo?: string | null;
  @field('encrypted') encrypted?: number;

  @field('sender_name') senderName?: string | null;
  @field('sender_avatar') senderAvatar?: string | null;
  @field('is_dirty') isDirty!: boolean;
  @field('dirty_actions') dirtyActions!: string | null;
  @field('is_sending') isSending?: boolean;
}
