// Author: fengshengxiong
// Date: 2024/6/4
// Description: 音频模型

import 'dart:convert';

import 'package:hive/hive.dart';

part 'voice_model.g.dart';

@HiveType(typeId: 0)
class VoiceModel extends HiveObject {
  @HiveField(0)
  String name;

  @HiveField(1)
  String path;

  @HiveField(2)
  String? cover;

  VoiceModel({
    required this.name,
    required this.path,
    this.cover,
  });

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

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

  VoiceModel copyWith({
    String? name,
    String? path,
    String? cover,
  }) =>
      VoiceModel(
        name: name ?? this.name,
        path: path ?? this.path,
        cover: cover ?? this.cover,
      );

  factory VoiceModel.fromMap(Map<String, dynamic> json) => VoiceModel(
    name: json["name"],
    path: json["path"],
    cover: json["cover"],
  );

  Map<String, dynamic> toMap() => {
    "name": name,
    "path": path,
    "cover": cover,
  };
}
