import 'package:get/get.dart';

class CategoryModel {
  int id;

  String icon;
  String cardCount;
  String enName;
  String arName;

  String get name {
    String locale = Get.locale!.languageCode;
    switch (locale) {
      case 'ar':
        return arName;
      case 'en':
        return enName;
    }
    return enName;
  }

  CategoryModel({
    required this.id,
    required this.enName,
    required this.arName,
    required this.icon,
    required this.cardCount,
  });

  factory CategoryModel.from(Map<String, dynamic> json) => CategoryModel(
        id: json["id"],
        enName: json["en_name"] ?? 'null_en',
        arName: json["ar_name"] ?? 'null_ar',
        icon: json["icon"],
        cardCount: json["card_count"].toString(),
      );

  static List<CategoryModel> fromJsonList(Map<String, dynamic> json) {
    List<CategoryModel> categories = [];

    json["data"].forEach(
      (element) => categories.add(
        CategoryModel.from(element),
      ),
    );
    return categories;
  }

  bool compare(CategoryModel categoryModel) {
    if (id == categoryModel.id) {
      return true;
    }
    if (name == categoryModel.name) {
      return true;
    }
    if (icon == categoryModel.icon) {
      return true;
    }
    if (cardCount == categoryModel.cardCount) {
      return true;
    } else {
      return false;
    }
  }

  factory CategoryModel.zero() => CategoryModel(
      id: 0,
      enName: 'category'.tr,
      arName: 'category'.tr,
      icon: '',
      cardCount: '');
}
