import 'package:hive/hive.dart';
import 'package:wallpaperx/entity/tags_model.dart';

import 'generate_info_model.dart';
part 'image_model.g.dart';

@HiveType(typeId: 2)
class ImageModel {
	@HiveField(0)
  String? uuid;
	@HiveField(1)
  String? name;
	@HiveField(2)
  String? imageUrl;
	@HiveField(3)
  int? width;
	@HiveField(4)
  int? height;
	@HiveField(5)
  List<TagsModel>? tags;
	@HiveField(6)
  List<String>? tagsv2;
	@HiveField(7)
  GenerateInfoModel? generateInfo;
	@HiveField(8)
  String? createTime;
	@HiveField(9)
  int? likeCount;
	@HiveField(10)
  int? heat;

  ImageModel(
      {this.uuid,
      this.name,
      this.imageUrl,
      this.width,
      this.height,
      this.tags,
      this.tagsv2,
      this.generateInfo,
      this.createTime,
      this.likeCount,
      this.heat});

  ImageModel.fromJson(Map<String, dynamic> json) {
    uuid = json['uuid'];
    name = json['name'];
    imageUrl = json['image_url'];
    width = json['width'];
    height = json['height'];
    if (json['tags'] != null) {
      tags = <TagsModel>[];
      json['tags'].forEach((v) {
        tags!.add(TagsModel.fromJson(v));
      });
    }
    tagsv2 = json['tagsv2'].cast<String>();
    generateInfo = json['generate_info'] != null
        ? GenerateInfoModel.fromJson(json['generate_info'])
        : null;
    createTime = json['create_time'];
    likeCount = json['like_count'];
    heat = json['heat'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['uuid'] = uuid;
    data['name'] = name;
    data['image_url'] = imageUrl;
    data['width'] = width;
    data['height'] = height;
    if (tags != null) {
      data['tags'] = tags!.map((v) => v.toJson()).toList();
    }
    data['tagsv2'] = tagsv2;
    if (generateInfo != null) {
      data['generate_info'] = generateInfo!.toJson();
    }
    data['create_time'] = createTime;
    data['like_count'] = likeCount;
    data['heat'] = heat;
    return data;
  }
}
