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

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

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

class Data {
  final int currentPage;
  final int totalPages;
  final int totalEntities;
  final List<Branch> data;

  Data({
    required this.currentPage,
    required this.totalPages,
    required this.totalEntities,
    required this.data,
  });

  factory Data.fromJson(Map<String, dynamic> json) {
    return Data(
      currentPage: json['currentPage'] ?? 0,
      totalPages: json['totalPages'] ?? 0,
      totalEntities: json['totalEntities'] ?? 0,
      data: json['data'] != null
          ? List<Branch>.from(
              json['data'].map((x) => Branch.fromJson(x)),
            )
          : [],
    );
  }
}

class Branch {
  final String id;
  final String branchName;
  final Project project;
  final String? contactInformation;
  final String? address;
  final String? branchType;
  final DateTime? createdAt;
  final CreatedBy? createdBy;

  Branch({
    required this.id,
    required this.branchName,
    required this.project,
    this.contactInformation,
    this.address,
    this.branchType,
    this.createdAt,
    this.createdBy,
  });

  factory Branch.fromJson(Map<String, dynamic> json) {
    return Branch(
      id: json['id'] ?? '',
      branchName: json['branchName'] ?? '',
      project: Project.fromJson(json['project'] ?? {}),
      contactInformation: json['contactInformation'],
      address: json['address'],
      branchType: json['branchType'],
      createdAt:
          json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null,
      createdBy:
          json['createdBy'] != null ? CreatedBy.fromJson(json['createdBy']) : null,
    );
  }
}

class Project {
  final String id;
  final String name;
  final String shortName;
  final DateTime? assignedDate;

  Project({
    required this.id,
    required this.name,
    required this.shortName,
    this.assignedDate,
  });

  factory Project.fromJson(Map<String, dynamic> json) {
    return Project(
      id: json['id'] ?? '',
      name: json['name'] ?? '',
      shortName: json['shortName'] ?? '',
      assignedDate: json['assignedDate'] != null
          ? DateTime.parse(json['assignedDate'])
          : null,
    );
  }
}

class CreatedBy {
  final String id;
  final String firstName;
  final String lastName;
  final String email;
  final String? photo;
  final String jobRoleId;
  final String jobRoleName;

  CreatedBy({
    required this.id,
    required this.firstName,
    required this.lastName,
    required this.email,
    this.photo,
    required this.jobRoleId,
    required this.jobRoleName,
  });

  factory CreatedBy.fromJson(Map<String, dynamic> json) {
    return CreatedBy(
      id: json['id'] ?? '',
      firstName: json['firstName'] ?? '',
      lastName: json['lastName'] ?? '',
      email: json['email'] ?? '',
      photo: json['photo'],
      jobRoleId: json['jobRoleId'] ?? '',
      jobRoleName: json['jobRoleName'] ?? '',
    );
  }
}
