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

/// 收藏小程序 DTO
class FavoriteMiniAppDto {
  final String id;
  final String? name;
  final String? openuid;
  final String? devId;
  final String? icon;
  final String? iconGaussian;
  final String? downloadUrl;
  final String? description;
  final int? version;
  final int? typ;
  final int? flag;
  final int? reviewStatus;
  final int? favoriteAt;
  final int? isActive;
  final int? createdAt;
  final int? updatedAt;
  final int? deletedAt;
  final double? score;
  final String? channels;
  final String? devName;
  final String? pictureGaussian;
  final String? picture;
  final int? commentNum;
  final int? lastLoginAt;
  final String? screen;

  const FavoriteMiniAppDto({
    required this.id,
    this.name,
    this.openuid,
    this.devId,
    this.icon,
    this.iconGaussian,
    this.downloadUrl,
    this.description,
    this.version,
    this.typ,
    this.flag,
    this.reviewStatus,
    this.favoriteAt,
    this.isActive,
    this.createdAt,
    this.updatedAt,
    this.deletedAt,
    this.score,
    this.channels,
    this.devName,
    this.pictureGaussian,
    this.picture,
    this.commentNum,
    this.lastLoginAt,
    this.screen,
  });

  factory FavoriteMiniAppDto.fromJson(Map<String, dynamic> json) =>
      FavoriteMiniAppDto(
        id: json['id'] as String,
        name: json['name'],
        openuid: json['openuid'],
        devId: json['dev_id'],
        icon: json['icon'],
        iconGaussian: json['icon_gaussian'],
        downloadUrl: json['download_url'],
        description: json['description'],
        version: json['version'],
        typ: json['typ'],
        flag: json['flag'],
        reviewStatus: json['review_status'],
        favoriteAt: json['favorite_at'],
        isActive: json['is_active'],
        createdAt: json['created_at'],
        updatedAt: json['updated_at'],
        deletedAt: json['deleted_at'],
        score: json['score']?.toDouble(),
        channels: json['channels'],
        devName: json['dev_name'],
        pictureGaussian: json['picture_gaussian'],
        picture: json['picture'],
        commentNum: json['comment_num'],
        lastLoginAt: json['last_login_at'],
        screen: json['screen'],
      );

  Map<String, dynamic> toJson() => {
    'id': id,
    'name': name,
    'openuid': openuid,
    'dev_id': devId,
    'icon': icon,
    'icon_gaussian': iconGaussian,
    'download_url': downloadUrl,
    'description': description,
    'version': version,
    'typ': typ,
    'flag': flag,
    'review_status': reviewStatus,
    'favorite_at': favoriteAt,
    'is_active': isActive,
    'created_at': createdAt,
    'updated_at': updatedAt,
    'deleted_at': deletedAt,
    'score': score,
    'channels': channels,
    'dev_name': devName,
    'picture_gaussian': pictureGaussian,
    'picture': picture,
    'comment_num': commentNum,
    'last_login_at': lastLoginAt,
    'screen': screen,
  };

  FavoriteMiniApp toEntity() => FavoriteMiniApp(
    id: id,
    name: name,
    openuid: openuid,
    devId: devId,
    icon: icon,
    iconGaussian: iconGaussian,
    downloadUrl: downloadUrl,
    description: description,
    version: version,
    typ: typ,
    flag: flag,
    reviewStatus: reviewStatus,
    favoriteAt: favoriteAt,
    isActive: isActive,
    createdAt: createdAt,
    updatedAt: updatedAt,
    deletedAt: deletedAt,
    score: score,
    channels: channels,
    devName: devName,
    pictureGaussian: pictureGaussian,
    picture: picture,
    commentNum: commentNum,
    lastLoginAt: lastLoginAt,
    screen: screen,
  );

  factory FavoriteMiniAppDto.fromEntity(FavoriteMiniApp app) =>
      FavoriteMiniAppDto(
        id: app.id,
        name: app.name,
        openuid: app.openuid,
        devId: app.devId,
        icon: app.icon,
        iconGaussian: app.iconGaussian,
        downloadUrl: app.downloadUrl,
        description: app.description,
        version: app.version,
        typ: app.typ,
        flag: app.flag,
        reviewStatus: app.reviewStatus,
        favoriteAt: app.favoriteAt,
        isActive: app.isActive,
        createdAt: app.createdAt,
        updatedAt: app.updatedAt,
        deletedAt: app.deletedAt,
        score: app.score,
        channels: app.channels,
        devName: app.devName,
        pictureGaussian: app.pictureGaussian,
        picture: app.picture,
        commentNum: app.commentNum,
        lastLoginAt: app.lastLoginAt,
        screen: app.screen,
      );

  FavoriteMiniAppsCompanion toCompanion() => FavoriteMiniAppsCompanion(
    id: Value(id),
    name: Value(name),
    openuid: Value(openuid),
    devId: Value(devId),
    icon: Value(icon),
    iconGaussian: Value(iconGaussian),
    downloadUrl: Value(downloadUrl),
    description: Value(description),
    version: Value(version),
    typ: Value(typ),
    flag: Value(flag),
    reviewStatus: Value(reviewStatus),
    favoriteAt: Value(favoriteAt),
    isActive: Value(isActive),
    createdAt: Value(createdAt),
    updatedAt: Value(updatedAt),
    deletedAt: Value(deletedAt),
    score: Value(score),
    channels: Value(channels),
    devName: Value(devName),
    pictureGaussian: Value(pictureGaussian),
    picture: Value(picture),
    commentNum: Value(commentNum),
    lastLoginAt: Value(lastLoginAt),
    screen: Value(screen),
  );
}
