class Leave {
  final int id;
  final String userId;
  final String startDate;
  final String endDate;
  final String reason;
  final String status;
  final String? approvedBy;
  final String? approvedAt;
  final String? rejectedBy;
  final String? rejectedAt;
  final String createdAt;
  final String updatedAt;

  Leave({
    required this.id,
    required this.userId,
    required this.startDate,
    required this.endDate,
    required this.reason,
    required this.status,
    this.approvedBy,
    this.approvedAt,
    this.rejectedBy,
    this.rejectedAt,
    required this.createdAt,
    required this.updatedAt,
  });

  factory Leave.fromJson(Map<String, dynamic> json) {
    return Leave(
      id: json['id'],
      userId: json['user_id'].toString(),
      startDate: json['tanggal_mulai'],
      endDate: json['tanggal_selesai'],
      reason: json['keterangan'],
      status: json['status'] ?? 'Pending',
      approvedBy: json['approved_by'],
      approvedAt: json['approved_at'],
      rejectedBy: json['rejected_by'],
      rejectedAt: json['rejected_at'],
      createdAt: json['created_at'],
      updatedAt: json['updated_at'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'user_id': userId,
      'tanggal_mulai': startDate,
      'tanggal_selesai': endDate,
      'keterangan': reason,
      'status': status,
      'approved_by': approvedBy,
      'approved_at': approvedAt,
      'rejected_by': rejectedBy,
      'rejected_at': rejectedAt,
      'created_at': createdAt,
      'updated_at': updatedAt,
    };
  }
} 