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

/// 用户请求历史 DTO
class UserRequestHistoryDto {
  final int id;
  final int? status;
  final int? createdAt;

  const UserRequestHistoryDto({
    required this.id,
    this.status,
    this.createdAt,
  });

  factory UserRequestHistoryDto.fromJson(Map<String, dynamic> json) =>
      UserRequestHistoryDto(
        id: json['id'] as int,
        status: json['status'],
        createdAt: json['created_at'],
      );

  Map<String, dynamic> toJson() => {
    'id': id,
    'status': status,
    'created_at': createdAt,
  };

  UserRequestHistory toEntity() => UserRequestHistory(
    id: id,
    status: status,
    createdAt: createdAt,
  );

  factory UserRequestHistoryDto.fromEntity(UserRequestHistory history) =>
      UserRequestHistoryDto(
        id: history.id,
        status: history.status,
        createdAt: history.createdAt,
      );

  UserRequestHistoriesCompanion toCompanion() =>
      UserRequestHistoriesCompanion(
        id: Value(id),
        status: Value(status),
        createdAt: Value(createdAt),
      );
}