class CompanyOffer {
  final String id;
  final String title;
  final String? description;
  final String type; // PERCENTAGE | FIXED_AMOUNT | FREE_DAY | SPECIAL_RATE
  final int discountValue;
  final String? promoCode;
  final bool isActive;
  final bool isPublic;
  final bool isFeatured;
  final DateTime validFrom;
  final DateTime validUntil;
  final int? maxRedemptions;
  final int redemptionCount;
  final List<String> categories;

  const CompanyOffer({
    required this.id,
    required this.title,
    this.description,
    required this.type,
    required this.discountValue,
    this.promoCode,
    required this.isActive,
    required this.isPublic,
    required this.isFeatured,
    required this.validFrom,
    required this.validUntil,
    this.maxRedemptions,
    required this.redemptionCount,
    required this.categories,
  });

  String get discountLabel {
    switch (type) {
      case 'PERCENTAGE':
        return '$discountValue% off';
      case 'FIXED_AMOUNT':
        return '\$${(discountValue / 100).toStringAsFixed(0)} off';
      case 'FREE_DAY':
        return '$discountValue free day${discountValue == 1 ? '' : 's'}';
      case 'SPECIAL_RATE':
        return 'Special rate';
      default:
        return 'Offer';
    }
  }

  factory CompanyOffer.fromJson(Map<String, dynamic> json) => CompanyOffer(
        id: json['id'] as String,
        title: json['title'] as String,
        description: json['description'] as String?,
        type: json['type'] as String? ?? 'PERCENTAGE',
        discountValue: json['discountValue'] as int? ?? 0,
        promoCode: json['promoCode'] as String?,
        isActive: json['isActive'] as bool? ?? true,
        isPublic: json['isPublic'] as bool? ?? false,
        isFeatured: json['isFeatured'] as bool? ?? false,
        validFrom: DateTime.parse(json['validFrom'] as String),
        validUntil: DateTime.parse(json['validUntil'] as String),
        maxRedemptions: json['maxRedemptions'] as int?,
        redemptionCount: json['redemptionCount'] as int? ?? 0,
        categories: (json['categories'] as List<dynamic>?)
                ?.map((e) => e as String)
                .toList() ??
            [],
      );
}
