import 'package:comwell_key_app/utils/json.dart';
import 'package:json_annotation/json_annotation.dart';

part '../../../.generated/up_sales/models/dto/addon_upgrade_dto.g.dart';

@JsonSerializable()
class AddOnUpgradeDTO {
  final String id;
  final String name;
  final int price;
  final String currency;
  final bool isSelected;
  @JsonKey(fromJson: _imagesFromJson)
  final List<String> images;
  final String description;
  final int quantity;
  final bool isService;
  final bool isPopular;
  final bool onlyAvailableBeforeCheckin;
  @JsonKey(defaultValue: '')
  final String animationJson;
  @JsonKey(defaultValue: '')
  final String backgroundImageUrl;

  AddOnUpgradeDTO({
    required this.id,
    required this.name,
    required this.price,
    required this.currency,
    required this.isSelected,
    required this.images,
    required this.description,
    this.quantity = 0,
    this.isService = false,
    this.isPopular = false,
    this.onlyAvailableBeforeCheckin = false,
    required this.animationJson,
    required this.backgroundImageUrl,
  });

  Json toJson() => _$AddOnUpgradeDTOToJson(this);

  factory AddOnUpgradeDTO.fromJson(Map<String, dynamic> json) => _$AddOnUpgradeDTOFromJson(json);
  static List<String> _imagesFromJson(List<dynamic>? images) =>
      images?.whereType<String>().toList() ?? [];
}