class DashboardTasks {
  final bool success;
  final String message;
  final DashboardTasksData? data;
  final dynamic errors;
  final int statusCode;
  final DateTime timestamp;

  DashboardTasks({
    required this.success,
    required this.message,
    required this.data,
    this.errors,
    required this.statusCode,
    required this.timestamp,
  });

  factory DashboardTasks.fromJson(Map<String, dynamic> json) {
    return DashboardTasks(
      success: json['success'] ?? false,
      message: json['message'] ?? '',
      data: json['data'] != null ? DashboardTasksData.fromJson(json['data']) : null,
      errors: json['errors'],
      statusCode: json['statusCode'] ?? 0,
      timestamp: DateTime.tryParse(json['timestamp'] ?? '') ?? DateTime.now(),
    );
  }
}

class DashboardTasksData {
  final int totalTasks;
  final int completedTasks;

  DashboardTasksData({
    required this.totalTasks,
    required this.completedTasks,
  });

  factory DashboardTasksData.fromJson(Map<String, dynamic> json) {
    int toInt(dynamic value) {
      if (value is int) return value;
      if (value is double) return value.toInt();
      if (value is String) return int.tryParse(value) ?? 0;
      return 0;
    }

    return DashboardTasksData(
      totalTasks: toInt(json['totalTasks']),
      completedTasks: toInt(json['completedTasks']),
    );
  }
}
