class NctProduct {
  final int? id;
  final String? nameRu;
  final String? nameKk;
  final String? gtin;
  final String? ntinCode;
  final bool? isSocial;
  final int? status;
  final bool? isMarkedEac;
  final String? measure;
  final bool? ntinIsDeactivated;
  final String? ntinDeactivationReason;
  final String? ntinDuplicateOfProduct;

  NctProduct({
    this.id,
    this.nameRu,
    this.nameKk,
    this.gtin,
    this.ntinCode,
    this.isSocial,
    this.status,
    this.isMarkedEac,
    this.measure,
    this.ntinIsDeactivated,
    this.ntinDeactivationReason,
    this.ntinDuplicateOfProduct,
  });

  factory NctProduct.fromJson(Map<String, dynamic> json) {
    return NctProduct(
      id: json['id'] is int ? json['id'] as int : null,
      nameRu: json['name_ru'] is String ? json['name_ru'] as String : null,
      nameKk: json['name_kk'] is String ? json['name_kk'] as String : null,
      gtin: json['gtin'] is String ? json['gtin'] as String : null,
      ntinCode: json['ntin_code'] is String ? json['ntin_code'] as String : null,
      isSocial: json['is_social'] is bool ? json['is_social'] as bool : null,
      status: json['status'] is int ? json['status'] as int : null,
      isMarkedEac: json['is_markedeac'] is bool ? json['is_markedeac'] as bool : null,
      measure: _parseStringOrObject(json['measure']),
      ntinIsDeactivated: json['ntin_isdeactivated'] is bool ? json['ntin_isdeactivated'] as bool : null,
      ntinDeactivationReason: _parseStringOrObject(json['ntin_deactivationreason']),
      ntinDuplicateOfProduct: _parseStringOrObject(json['ntin_duplicateofproduct']),
    );
  }

  static String? _parseStringOrObject(dynamic value) {
    if (value == null) return null;
    if (value is String) return value;
    if (value is Map) return value['name_ru']?.toString() ?? value['name']?.toString() ?? value.toString();
    return value.toString();
  }
}
