import 'dart:convert';

import 'package:hive/hive.dart';

part 'history_model.g.dart';

@HiveType(typeId: 1)
class HistoryModel 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;

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

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

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

  HistoryModel copyWith({
    int? translationTime,
    String? sourceText,
    String? targetText,
    String? sourceLanguageName,
    String? sourceLanguageCode,
    String? targetLanguageName,
    String? targetLanguageCode,
  }) =>
      HistoryModel(
        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 HistoryModel.fromMap(Map<String, dynamic> json) => HistoryModel(
    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,
  };
}