class Event {
  final String id;
  final String clubId;
  final String title;
  final String? description;
  final DateTime startDate;
  final DateTime? endDate;
  final String? location;
  final String? type;
  final String? status;
  final int? maxParticipants;
  final int? currentParticipants;
  final int? gameCount;
  final double? participantFee;
  final DateTime? registrationDeadline;
  final String? publicHash;
  final String? accessPassword;
  final bool isActive;
  final String? createdBy;
  final DateTime? createdAt;
  final DateTime? updatedAt;

  Event({
    required this.id,
    required this.clubId,
    required this.title,
    this.description,
    required this.startDate,
    this.endDate,
    this.location,
    this.type,
    this.status,
    this.maxParticipants,
    this.currentParticipants,
    this.gameCount,
    this.participantFee,
    this.registrationDeadline,
    this.publicHash,
    this.accessPassword,
    required this.isActive,
    this.createdBy,
    this.createdAt,
    this.updatedAt,
  });

  // JSON 데이터로부터 Event 객체 생성
  factory Event.fromJson(Map<String, dynamic> json) {
    return Event(
      id: json['id']?.toString() ?? '',
      clubId: json['clubId']?.toString() ?? '',
      title: json['title'] ?? '',
      description: json['description']?.toString(),
      startDate: json['startDate'] != null ? DateTime.parse(json['startDate'].toString()) : DateTime.now(),
      endDate: json['endDate'] != null ? DateTime.parse(json['endDate'].toString()) : null,
      location: json['location']?.toString(),
      type: json['type']?.toString(),
      status: json['status']?.toString(),
      maxParticipants: json['maxParticipants'],
      currentParticipants: json['currentParticipants'],
      gameCount: json['gameCount'],
      participantFee: json['participantFee'] != null ? double.tryParse(json['participantFee'].toString()) : null,
      registrationDeadline: json['registrationDeadline'] != null ? DateTime.parse(json['registrationDeadline'].toString()) : null,
      publicHash: json['publicHash']?.toString(),
      accessPassword: json['accessPassword']?.toString(),
      isActive: json['isActive'] ?? true,
      createdBy: json['createdBy']?.toString(),
      createdAt: json['createdAt'] != null ? DateTime.parse(json['createdAt'].toString()) : null,
      updatedAt: json['updatedAt'] != null ? DateTime.parse(json['updatedAt'].toString()) : null,
    );
  }

  // Event 객체를 JSON으로 변환
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'clubId': clubId,
      'title': title,
      'description': description,
      'startDate': startDate.toIso8601String(),
      'endDate': endDate?.toIso8601String(),
      'location': location,
      'type': type,
      'status': status,
      'maxParticipants': maxParticipants,
      'currentParticipants': currentParticipants,
      'gameCount': gameCount,
      'participantFee': participantFee,
      'registrationDeadline': registrationDeadline?.toIso8601String(),
      'publicHash': publicHash,
      'accessPassword': accessPassword,
      'isActive': isActive,
      'createdBy': createdBy,
      'createdAt': createdAt?.toIso8601String(),
      'updatedAt': updatedAt?.toIso8601String(),
    };
  }
}
