// lib/features/booking/models/booking_models.dart

class TicketMetaModel {
  final int id;
  final int eventId;
  final String ticketType;
  final double price;
  final int availableQuantity;
  final String? description;

  const TicketMetaModel({
    required this.id,
    required this.eventId,
    required this.ticketType,
    required this.price,
    this.availableQuantity = 0,
    this.description,
  });

  factory TicketMetaModel.fromJson(Map<String, dynamic> json) {
    return TicketMetaModel(
      id: (json['id'] as num?)?.toInt() ?? 0,
      eventId: (json['event_id'] as num?)?.toInt() ?? (json['event'] as num?)?.toInt() ?? 0,
      ticketType: json['ticket_type'] as String? ?? json['name'] as String? ?? '',
      price: (json['price'] as num?)?.toDouble() ?? 0.0,
      availableQuantity: (json['available_quantity'] as num?)?.toInt() ?? 0,
      description: json['description'] as String?,
    );
  }
}

class CartItemModel {
  final TicketMetaModel ticket;
  int quantity;

  CartItemModel({required this.ticket, this.quantity = 1});

  double get subtotal => ticket.price * quantity;
}

class ShippingDetails {
  final String name;
  final String email;
  final String phone;
  final String? address;
  final String? city;
  final String? state;
  final String? zipCode;

  const ShippingDetails({
    required this.name,
    required this.email,
    required this.phone,
    this.address,
    this.city,
    this.state,
    this.zipCode,
  });

  Map<String, dynamic> toJson() => {
    'name': name,
    'email': email,
    'phone': phone,
    if (address != null) 'address': address,
    if (city != null) 'city': city,
    if (state != null) 'state': state,
    if (zipCode != null) 'zip_code': zipCode,
  };
}

class OrderSummary {
  final List<CartItemModel> items;
  final double subtotal;
  final double discount;
  final double tax;
  final double total;
  final String? couponCode;

  const OrderSummary({
    required this.items,
    required this.subtotal,
    this.discount = 0,
    this.tax = 0,
    required this.total,
    this.couponCode,
  });
}
