// lib/models/event.dart

class Event {
  final int id;
  final String eventName;
  final DateTime startDatetime;
  final DateTime endDatetime;
  final DateTime deadlineDateTime; // 新しく追加

  Event({
    required this.id,
    required this.eventName,
    required this.startDatetime,
    required this.endDatetime,
    required this.deadlineDateTime,
  });

  factory Event.fromJson(Map<String, dynamic> json) {
    final endDatetime = DateTime.parse(json['end_datetime']);
    return Event(
      id: json['id'],
      eventName: json['event_name'],
      startDatetime: DateTime.parse(json['start_datetime']),
      endDatetime: DateTime.parse(json['end_datetime']),
      deadlineDateTime: json['deadline_datetime'] != null
          ? DateTime.parse(json['deadline_datetime'])
          : endDatetime.subtract(const Duration(days: 7)), // 仮の実装
      // deadlineDateTime: DateTime.parse(json['deadline_datetime']),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'event_name': eventName,
      'start_datetime': startDatetime.toIso8601String(),
      'end_datetime': endDatetime.toIso8601String(),
    };
  }
}