import 'package:drift/drift.dart';
import 'package:im_app/data/local/drift/app_database.dart';
import 'package:im_app/domain/entities/favourite_detail.dart';

/// 收藏详情 DTO
class FavouriteDetailDto {
  final int? id;
  final String relatedId;
  final String content;
  final int? typ;
  final int? messageId;
  final int? sendId;
  final int? chatId;
  final int? sendTime;

  const FavouriteDetailDto({
    this.id,
    this.relatedId = '',
    this.content = '',
    this.typ,
    this.messageId,
    this.sendId,
    this.chatId,
    this.sendTime,
  });

  factory FavouriteDetailDto.fromJson(Map<String, dynamic> json) =>
      FavouriteDetailDto(
        id: json['id'],
        relatedId: json['related_id'] ?? '',
        content: json['content'] ?? '',
        typ: json['typ'],
        messageId: json['messageId'],
        sendId: json['sendId'],
        chatId: json['chatId'],
        sendTime: json['sendTime'],
      );

  Map<String, dynamic> toJson() => {
    'id': id,
    'related_id': relatedId,
    'content': content,
    'typ': typ,
    'messageId': messageId,
    'sendId': sendId,
    'chatId': chatId,
    'sendTime': sendTime,
  };

  FavouriteDetail toEntity() => FavouriteDetail(
    id: id,
    relatedId: relatedId,
    content: content,
    typ: typ,
    messageId: messageId,
    sendId: sendId,
    chatId: chatId,
    sendTime: sendTime,
  );

  factory FavouriteDetailDto.fromEntity(FavouriteDetail detail) =>
      FavouriteDetailDto(
        id: detail.id,
        relatedId: detail.relatedId,
        content: detail.content,
        typ: detail.typ,
        messageId: detail.messageId,
        sendId: detail.sendId,
        chatId: detail.chatId,
        sendTime: detail.sendTime,
      );

  FavouriteDetailsCompanion toCompanion() => FavouriteDetailsCompanion(
    id: id != null ? Value(id!) : const Value.absent(),
    relatedId: Value(relatedId),
    content: Value(content),
    typ: Value(typ),
    messageId: Value(messageId),
    sendId: Value(sendId),
    chatId: Value(chatId),
    sendTime: Value(sendTime),
  );
}