class Currency {
  final int id;
  final String title;
  final String currency;
  final String code;
  final bool isBase;
  final int denomination;
  final double exchangeRate;
  final String formatString;
  final String floatSeparator;
  final int decimals;
  final bool isHideZero;

  Currency({
    required this.id,
    required this.title,
    required this.currency,
    required this.code,
    required this.isBase,
    required this.denomination,
    required this.exchangeRate,
    required this.formatString,
    required this.floatSeparator,
    required this.decimals,
    required this.isHideZero,
  });

  factory Currency.fromJson(Map<String, dynamic> json) {
    return Currency(
      id: json['id'] as int,
      title: json['title'] as String,
      currency: json['currency'] as String,
      code: json['code'] as String,
      isBase: json['isBase'] as bool,
      denomination: json['denomination'] as int,
      exchangeRate: (json['exchangeRate'] as num).toDouble(),
      formatString: json['formatString'] as String,
      floatSeparator: json['floatSeparator'] as String,
      decimals: json['decimals'] as int,
      isHideZero: json['isHideZero'] as bool,
    );
  }
}

class Certificate {
  final int id;
  final String title;
  final String? description;
  final double price;
  final int currencyId;
  final int value;
  final double discount;
  final DateTime createdAt;
  final DateTime updatedAt;
  final int sort;
  final bool isActive;
  final Currency? currency;
  final String? pricePrint;

  Certificate({
    required this.id,
    required this.title,
    this.description,
    required this.price,
    required this.currencyId,
    required this.value,
    required this.discount,
    required this.createdAt,
    required this.updatedAt,
    required this.sort,
    required this.isActive,
    this.currency,
    this.pricePrint,
  });

  factory Certificate.fromJson(Map<String, dynamic> json) {
    return Certificate(
      id: json['id'] as int,
      title: json['title'] as String,
      description: json['description'] as String?,
      price: (json['price'] as num).toDouble(),
      currencyId: json['currencyId'] as int,
      value: json['value'] as int,
      discount: (json['discount'] as num).toDouble(),
      createdAt: DateTime.parse(json['createdAt'] as String),
      updatedAt: DateTime.parse(json['updatedAt'] as String),
      sort: json['sort'] as int,
      isActive: json['isActive'] as bool,
      currency: json['currency'] != null ? Currency.fromJson(json['currency']) : null,
      pricePrint: json['pricePrint'] as String?,
    );
  }

}
