import 'dart:convert';

import 'package:hive/hive.dart';

part 'history_model.g.dart';

@HiveType(typeId: 1)
class HistoryEntity extends HiveObject {
  @HiveField(1)
  int? translationTime;

  @HiveField(2)
  String? sourceText;

  @HiveField(3)
  String? targetText;

  @HiveField(4)
  String? sourceLanguageName;

  @HiveField(5)
  String? sourceLanguageCode;

  @HiveField(6)
  String? targetLanguageName;

  @HiveField(7)
  String? targetLanguageCode;

  HistoryEntity({
    this.translationTime,
    this.sourceText,
    this.targetText,
    this.sourceLanguageName,
    this.sourceLanguageCode,
    this.targetLanguageName,
    this.targetLanguageCode,
  });

  HistoryEntity fromJson(String str) => HistoryEntity.fromMap(json.decode(str));

  String toJson() => json.encode(toMap());

  HistoryEntity copyWith({
    int? translationTime,
    String? sourceText,
    String? targetText,
    String? sourceLanguageName,
    String? sourceLanguageCode,
    String? targetLanguageName,
    String? targetLanguageCode,
  }) =>
      HistoryEntity(
        translationTime: translationTime ?? this.translationTime,
        sourceText: sourceText ?? this.sourceText,
        targetText: targetText ?? this.targetText,
        sourceLanguageName: sourceLanguageName ?? this.sourceLanguageName,
        sourceLanguageCode: sourceLanguageCode ?? this.sourceLanguageCode,
        targetLanguageName: targetLanguageName ?? this.targetLanguageName,
        targetLanguageCode: targetLanguageCode ?? this.targetLanguageCode,
      );

  factory HistoryEntity.fromMap(Map<String, dynamic> json) => HistoryEntity(
    translationTime: json["translationTime"],
    sourceText: json["sourceText"],
    targetText: json["targetText"],
    sourceLanguageName: json["sourceLanguageName"],
    sourceLanguageCode: json["sourceLanguageCode"],
    targetLanguageName: json["targetLanguageName"],
    targetLanguageCode: json["targetLanguageCode"],
  );

  Map<String, dynamic> toMap() => {
    "translationTime": translationTime,
    "sourceText": sourceText,
    "targetText": targetText,
    "sourceLanguageName": sourceLanguageName,
    "sourceLanguageCode": sourceLanguageCode,
    "targetLanguageName": targetLanguageName,
    "targetLanguageCode": targetLanguageCode,
  };
}