/// Model de données Message avec sérialisation JSON
library message_model;

import 'package:json_annotation/json_annotation.dart';
import '../../domain/entities/message.dart';

part 'message_model.g.dart';

@JsonSerializable(explicitToJson: true)
class MessageModel extends Message {
  const MessageModel({
    required super.id,
    required super.conversationId,
    required super.senderId,
    required super.senderName,
    super.senderAvatar,
    required super.content,
    required super.type,
    required super.status,
    super.priority,
    required super.recipientIds,
    super.recipientRoles,
    super.organizationId,
    required super.createdAt,
    super.readAt,
    super.metadata,
    super.attachments,
    super.isEdited,
    super.editedAt,
    super.isDeleted,
  });

  factory MessageModel.fromJson(Map<String, dynamic> json) =>
      _$MessageModelFromJson(json);

  Map<String, dynamic> toJson() => _$MessageModelToJson(this);

  factory MessageModel.fromEntity(Message message) {
    return MessageModel(
      id: message.id,
      conversationId: message.conversationId,
      senderId: message.senderId,
      senderName: message.senderName,
      senderAvatar: message.senderAvatar,
      content: message.content,
      type: message.type,
      status: message.status,
      priority: message.priority,
      recipientIds: message.recipientIds,
      recipientRoles: message.recipientRoles,
      organizationId: message.organizationId,
      createdAt: message.createdAt,
      readAt: message.readAt,
      metadata: message.metadata,
      attachments: message.attachments,
      isEdited: message.isEdited,
      editedAt: message.editedAt,
      isDeleted: message.isDeleted,
    );
  }

  Message toEntity() => Message(
    id: id,
    conversationId: conversationId,
    senderId: senderId,
    senderName: senderName,
    senderAvatar: senderAvatar,
    content: content,
    type: type,
    status: status,
    priority: priority,
    recipientIds: recipientIds,
    recipientRoles: recipientRoles,
    organizationId: organizationId,
    createdAt: createdAt,
    readAt: readAt,
    metadata: metadata,
    attachments: attachments,
    isEdited: isEdited,
    editedAt: editedAt,
    isDeleted: isDeleted,
  );
}
