import 'package:get/get.dart';

class CityModel {
  int id;
  String enName;

  String arName;
  String enCountry;

  String arCountry;
  int countryId;

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

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

  CityModel({
    required this.id,
    required this.enName,
    required this.arName,
    required this.arCountry,
    required this.enCountry,
    required this.countryId,
  });

  factory CityModel.fromJson(Map<String, dynamic> json) => CityModel(
        id: json["id"],
        enName: json["en_name"],
        arName: json["ar_name"],
        countryId: json["country_id"],
        arCountry: json["country_ar"],
        enCountry: json["country_en"],
      );

  factory CityModel.zero() => CityModel(
      id: 0,
      enName: 'city'.tr,
      arName: 'city'.tr,
      arCountry: '',
      enCountry: '',
      countryId: 0);

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

    json["data"].forEach(
      (element) => cities.add(
        CityModel.fromJson(element),
      ),
    );
    return cities;
  }

  bool compare(CityModel cityModel) {
    if (id == cityModel.id) {
      return true;
    }
    if (name == cityModel.name) {
      return true;
    }
    if (countryId == cityModel.countryId) {
      return true;
    }
    if (country == cityModel.country) {
      return true;
    } else {
      return false;
    }
  }
}
