// Author: fengshengxiong
// Date: 2024/6/24
// Description: 音乐模型

import 'dart:convert';

import 'package:hive/hive.dart';

part 'music_model.g.dart';

@HiveType(typeId: 2)
class MusicModel extends HiveObject {
  @HiveField(0)
  String? title;
  @HiveField(1)
  String? subTitle;
  @HiveField(2)
  String? thumbnail;
  @HiveField(3)
  String? videoId;
  @HiveField(4)
  String? playlistId;
  @HiveField(5)
  String? url;

  MusicModel({
    this.title,
    this.subTitle,
    this.thumbnail,
    this.videoId,
    this.playlistId,
    this.url,
  });

  MusicModel copyWith({
    String? title,
    String? subTitle,
    String? thumbnail,
    String? url,
    String? videoId,
    String? playlistId,
  }) =>
      MusicModel(
        title: title ?? this.title,
        subTitle: subTitle ?? this.subTitle,
        thumbnail: thumbnail ?? this.thumbnail,
        url: url ?? this.url,
        videoId: videoId ?? this.videoId,
        playlistId: playlistId ?? this.playlistId,
      );

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

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

  factory MusicModel.fromMap(Map<String, dynamic> json) => MusicModel(
        title: json["title"],
        subTitle: json["subTitle"],
        thumbnail: json["thumbnail"],
        videoId: json["videoId"],
        playlistId: json["playlistId"],
        url: json["url"],
      );

  Map<String, dynamic> toMap() => {
        "title": title,
        "subTitle": subTitle,
        "thumbnail": thumbnail,
        "videoId": videoId,
        "playlistId": playlistId,
        "url": url,
      };
}
