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

/// 聊天分类 DTO
class ChatCategoryDto {
  final int id;
  final String? name;
  final String? includedChatIds;
  final String? excludedChatIds;
  final int? seq;
  final int isHide;
  final int createdAt;
  final int updatedAt;
  final int deletedAt;

  const ChatCategoryDto({
    required this.id,
    this.name,
    this.includedChatIds,
    this.excludedChatIds,
    this.seq,
    this.isHide = 0,
    this.createdAt = 0,
    this.updatedAt = 0,
    this.deletedAt = 0,
  });

  factory ChatCategoryDto.fromJson(Map<String, dynamic> json) =>
      ChatCategoryDto(
        id: json['id'] as int,
        name: json['name'],
        includedChatIds: json['included_chat_ids'],
        excludedChatIds: json['excluded_chat_ids'],
        seq: json['seq'],
        isHide: json['is_hide'] ?? 0,
        createdAt: json['created_at'] ?? 0,
        updatedAt: json['updated_at'] ?? 0,
        deletedAt: json['deleted_at'] ?? 0,
      );

  Map<String, dynamic> toJson() => {
    'id': id,
    'name': name,
    'included_chat_ids': includedChatIds,
    'excluded_chat_ids': excludedChatIds,
    'seq': seq,
    'is_hide': isHide,
    'created_at': createdAt,
    'updated_at': updatedAt,
    'deleted_at': deletedAt,
  };

  ChatCategory toEntity() => ChatCategory(
    id: id,
    name: name,
    includedChatIds: includedChatIds,
    excludedChatIds: excludedChatIds,
    seq: seq,
    isHide: isHide,
    createdAt: createdAt,
    updatedAt: updatedAt,
    deletedAt: deletedAt,
  );

  factory ChatCategoryDto.fromEntity(ChatCategory chatCategory) =>
      ChatCategoryDto(
        id: chatCategory.id,
        name: chatCategory.name,
        includedChatIds: chatCategory.includedChatIds,
        excludedChatIds: chatCategory.excludedChatIds,
        seq: chatCategory.seq,
        isHide: chatCategory.isHide,
        createdAt: chatCategory.createdAt,
        updatedAt: chatCategory.updatedAt,
        deletedAt: chatCategory.deletedAt,
      );

  ChatCategoriesCompanion toCompanion() => ChatCategoriesCompanion(
    id: Value(id),
    name: Value(name),
    includedChatIds: Value(includedChatIds),
    excludedChatIds: Value(excludedChatIds),
    seq: Value(seq),
    isHide: Value(isHide),
    createdAt: Value(createdAt),
    updatedAt: Value(updatedAt),
    deletedAt: Value(deletedAt),
  );
}
