// Root Response Model
class ProjectsResponse {
  final bool? success;
  final String? message;
  final ProjectsPageData? data;
  final dynamic errors;
  final int? statusCode;
  final String? timestamp;

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

  factory ProjectsResponse.fromJson(Map<String, dynamic> json) {
    return ProjectsResponse(
      success: json['success'],
      message: json['message'],
      data: json['data'] != null
          ? ProjectsPageData.fromJson(json['data'])
          : null,
      errors: json['errors'],
      statusCode: json['statusCode'],
      timestamp: json['timestamp'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'success': success,
      'message': message,
      'data': data?.toJson(),
      'errors': errors,
      'statusCode': statusCode,
      'timestamp': timestamp,
    };
  }
}

// Pagination + Data List
class ProjectsPageData {
  final int? currentPage;
  final int? totalPages;
  final int? totalEntites;
  final List<ProjectData>? data;

  ProjectsPageData({
    this.currentPage,
    this.totalPages,
    this.totalEntites,
    this.data,
  });

  factory ProjectsPageData.fromJson(Map<String, dynamic> json) {
    return ProjectsPageData(
      currentPage: json['currentPage'],
      totalPages: json['totalPages'],
      totalEntites: json['totalEntites'],
      data: (json['data'] as List<dynamic>?)
          ?.map((e) => ProjectData.fromJson(e))
          .toList(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'currentPage': currentPage,
      'totalPages': totalPages,
      'totalEntites': totalEntites,
      'data': data?.map((e) => e.toJson()).toList(),
    };
  }
}

// Individual Project Model
class ProjectData {
  final String? id;
  final String? name;
  final String? shortName;
  final String? projectAddress;
  final String? contactPerson;
  final String? startDate;
  final String? endDate;
  final String? projectStatusId;
  final int? teamSize;
  final double? completedWork;
  final double? plannedWork;

  ProjectData({
    this.id,
    this.name,
    this.shortName,
    this.projectAddress,
    this.contactPerson,
    this.startDate,
    this.endDate,
    this.projectStatusId,
    this.teamSize,
    this.completedWork,
    this.plannedWork,
  });

  factory ProjectData.fromJson(Map<String, dynamic> json) {
    return ProjectData(
      id: json['id'],
      name: json['name'],
      shortName: json['shortName'],
      projectAddress: json['projectAddress'],
      contactPerson: json['contactPerson'],
      startDate: json['startDate'],
      endDate: json['endDate'],
      projectStatusId: json['projectStatusId'],
      teamSize: json['teamSize'],
      completedWork: (json['completedWork'] as num?)?.toDouble(),
      plannedWork: (json['plannedWork'] as num?)?.toDouble(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'shortName': shortName,
      'projectAddress': projectAddress,
      'contactPerson': contactPerson,
      'startDate': startDate,
      'endDate': endDate,
      'projectStatusId': projectStatusId,
      'teamSize': teamSize,
      'completedWork': completedWork,
      'plannedWork': plannedWork,
    };
  }
}
