class ScanHistoryDetails {
  final int id;
  final String qrCode;
  final String qrNumber;
  final String status;
  final String reason;
  final int partnerId;
  final int attractionId;
  final String attractionTitle;
  final String cityName;
  final String bookingNumber;
  final String customerName;
  final String customerMobile;
  final String customerEmail;
  final String cardType;
  final int scannedByPartnerStaffId;
  final String scannedByPartnerStaffName;
  final String validUpto;
  final String activatedAt;
  final String checkedInDatetime;
  final String qrExpiresAt;
  final String createdAt;
  final String updatedAt;

  ScanHistoryDetails({
    required this.id,
    required this.qrCode,
    required this.qrNumber,
    required this.status,
    required this.reason,
    required this.partnerId,
    required this.attractionId,
    required this.attractionTitle,
    required this.cityName,
    required this.bookingNumber,
    required this.customerName,
    required this.customerMobile,
    required this.customerEmail,
    required this.cardType,
    required this.scannedByPartnerStaffId,
    required this.scannedByPartnerStaffName,
    required this.validUpto,
    required this.activatedAt,
    required this.checkedInDatetime,
    required this.qrExpiresAt,
    required this.createdAt,
    required this.updatedAt,
  });

  /// ✅ Factory with N/A fallback
  factory ScanHistoryDetails.fromJson(Map<String, dynamic> json) {
    return ScanHistoryDetails(
      id: json['id'] ?? 0,

      qrCode: _value(json['qrCode']),
      qrNumber: _value(json['qrNumber']),
      status: _value(json['status']),
      reason: _value(json['reason']),

      partnerId: json['partnerId'] ?? 0,
      attractionId: json['attractionId'] ?? 0,

      attractionTitle: _value(json['attractionTitle']),
      cityName: _value(json['cityName']),
      bookingNumber: _value(json['bookingNumber']),

      customerName: _value(json['customerName']),
      customerMobile: _value(json['customerMobile']),
      customerEmail: _value(json['customerEmail']),
      cardType: _value(json['cardType']),

      scannedByPartnerStaffId: json['scannedByPartnerStaffId'] ?? 0,
      scannedByPartnerStaffName:
      _value(json['scannedByPartnerStaffName']),

      validUpto: _value(json['validUpto']),
      activatedAt: _value(json['activatedAt']),
      checkedInDatetime: _value(json['checkedInDatetime']),
      qrExpiresAt: _value(json['qrExpiresAt']),

      createdAt: _value(json['createdAt']),
      updatedAt: _value(json['updatedAt']),
    );
  }

  /// ✅ Convert back to JSON (optional but useful)
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'qrCode': qrCode,
      'qrNumber': qrNumber,
      'status': status,
      'reason': reason,
      'partnerId': partnerId,
      'attractionId': attractionId,
      'attractionTitle': attractionTitle,
      'cityName': cityName,
      'bookingNumber': bookingNumber,
      'customerName': customerName,
      'customerMobile': customerMobile,
      'customerEmail': customerEmail,
      'cardType': cardType,
      'scannedByPartnerStaffId': scannedByPartnerStaffId,
      'scannedByPartnerStaffName': scannedByPartnerStaffName,
      'validUpto': validUpto,
      'activatedAt': activatedAt,
      'checkedInDatetime': checkedInDatetime,
      'qrExpiresAt': qrExpiresAt,
      'createdAt': createdAt,
      'updatedAt': updatedAt,
    };
  }

  /// ✅ Common helper for null / empty / "null"
  static String _value(dynamic val) {
    if (val == null) return "N/A";
    if (val.toString().trim().isEmpty) return "N/A";
    if (val.toString().toLowerCase() == "null") return "N/A";
    return val.toString();
  }
}