class JobResponse {
  final bool success;
  final String message;
  final int statusCode;
  final String timestamp;
  final JobData? data;
  final dynamic errors;

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

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

class JobData {
  final int currentPage;
  final int totalPages;
  final int totalEntities;
  final List<JobEntity>? data;

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

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

class JobEntity {
  final String id;
  final String title;
  final String description;
  final Project project;
  final List<Assignee>? assignees;
  final Status status;
  final String startDate;
  final String dueDate;
  final bool isActive;
  final String createdAt;
  final CreatedBy createdBy;
  final List<Tag>? tags;

  JobEntity({
    required this.id,
    required this.title,
    required this.description,
    required this.project,
    this.assignees,
    required this.status,
    required this.startDate,
    required this.dueDate,
    required this.isActive,
    required this.createdAt,
    required this.createdBy,
    this.tags,
  });

  factory JobEntity.fromJson(Map<String, dynamic> json) {
    return JobEntity(
      id: json['id'] ?? '',
      title: json['title'] ?? '',
      description: json['description'] ?? '',
      project: Project.fromJson(json['project']),
      assignees: (json['assignees'] as List<dynamic>?)
          ?.map((e) => Assignee.fromJson(e))
          .toList(),
      status: Status.fromJson(json['status']),
      startDate: json['startDate'] ?? '',
      dueDate: json['dueDate'] ?? '',
      isActive: json['isActive'] ?? false,
      createdAt: json['createdAt'] ?? '',
      createdBy: CreatedBy.fromJson(json['createdBy']),
      tags: (json['tags'] as List<dynamic>?)
          ?.map((e) => Tag.fromJson(e))
          .toList(),
    );
  }
}

class Project {
  final String id;
  final String name;
  final String shortName;
  final String assignedDate;
  final String contactName;
  final String contactPhone;
  final String contactEmail;

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

  factory Project.fromJson(Map<String, dynamic> json) {
    return Project(
      id: json['id'] ?? '',
      name: json['name'] ?? '',
      shortName: json['shortName'] ?? '',
      assignedDate: json['assignedDate'] ?? '',
      contactName: json['contactName'] ?? '',
      contactPhone: json['contactPhone'] ?? '',
      contactEmail: json['contactEmail'] ?? '',
    );
  }
}

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

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

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

class Status {
  final String id;
  final String name;
  final String displayName;

  Status({
    required this.id,
    required this.name,
    required this.displayName,
  });

  factory Status.fromJson(Map<String, dynamic> json) {
    return Status(
      id: json['id'] ?? '',
      name: json['name'] ?? '',
      displayName: json['displayName'] ?? '',
    );
  }
}

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,
    required 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'] ?? '',
    );
  }
}

class Tag {
  final String id;
  final String name;

  Tag({
    required this.id,
    required this.name,
  });

  factory Tag.fromJson(Map<String, dynamic> json) {
    return Tag(
      id: json['id'] ?? '',
      name: json['name'] ?? '',
    );
  }
}
