class VacationResponseDto {
  final int statusCode;
  final bool isSuccess;
  final String message;
  final VacationDataDto? data;

  VacationResponseDto({
    required this.statusCode,
    required this.isSuccess,
    required this.message,
    this.data,
  });

  factory VacationResponseDto.fromJson(Map<String, dynamic> json) {
    return VacationResponseDto(
      statusCode: json['statusCode'] ?? 0,
      isSuccess: json['isSuccess'] ?? false,
      message: json['message'] ?? '',
      data: json['data'] != null ? VacationDataDto.fromJson(json['data']) : null,
    );
  }
}

class VacationDataDto {
  final String employeeId;
  final String? employeeFullName;
  final DateTime startDate;
  final DateTime endDate;
  final String reason;
  final String? submittedBy;
  final String? submittedByUser;
  final int state;
  final int type;
  final String id;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final DateTime? deletedAt;
  final bool? isDeleted;

  VacationDataDto({
    required this.employeeId,
    this.employeeFullName,
    required this.startDate,
    required this.endDate,
    required this.reason,
    this.submittedBy,
    this.submittedByUser,
    required this.state,
    required this.type,
    required this.id,
    this.createdAt,
    this.updatedAt,
    this.deletedAt,
    this.isDeleted,
  });

  factory VacationDataDto.fromJson(Map<String, dynamic> json) {
    return VacationDataDto(
      employeeId: json['employeeId']?.toString() ?? '',
      employeeFullName: json['employeeFullName'],
      startDate: _parseDateTime(json['startDate'])!,
      endDate: _parseDateTime(json['endDate'])!,
      reason: json['reason']?.toString() ?? '',
      submittedBy: json['submittedBy'],
      submittedByUser: json['submittedByUser'],
      state: json['state'] ?? 0,
      type: json['type'] ?? 0,
      id: json['id']?.toString() ?? '',
      createdAt: _parseDateTime(json['createdAt']),
      updatedAt: _parseDateTime(json['updatedAt']),
      deletedAt: _parseDateTime(json['deletedAt']),
      isDeleted: json['isDeleted'],
    );
  }

  static DateTime? _parseDateTime(dynamic value) {
    if (value == null) return null;
    if (value is DateTime) return value;
    if (value is String) {
      try {
        return DateTime.parse(value);
      } catch (e) {
        print('Error parsing date: $value - $e');
        return null;
      }
    }
    return null;
  }
}
