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

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

  factory JobDetailsResponse.fromJson(Map<String, dynamic>? json) {
    if (json == null) return JobDetailsResponse();

    return JobDetailsResponse(
      success: json['success'] as bool?,
      message: json['message'] as String?,
      data: json['data'] != null ? JobData.fromJson(json['data']) : null,
      errors: json['errors'],
      statusCode: json['statusCode'] as int?,
      timestamp: json['timestamp'] as String?,
    );
  }
}

class JobData {
  final String? id;
  final String? title;
  final String? description;
  final String? jobTicketUId;
  final Project? project;
  final List<Assignee>? assignees;
  final Status? status;
  final String? startDate;
  final String? dueDate;
  final bool? isActive;
  final dynamic taggingAction;
  final String? attendanceId;
  final int? nextTaggingAction;
  final String? createdAt;
  final User? createdBy;
  final List<Tag>? tags;
  final List<UpdateLog>? updateLogs;
  final ProjectBranch? projectBranch;

  JobData({
    this.id,
    this.title,
    this.description,
    this.jobTicketUId,
    this.project,
    this.assignees,
    this.status,
    this.startDate,
    this.dueDate,
    this.isActive,
    this.taggingAction,
    this.attendanceId,
    this.nextTaggingAction,
    this.createdAt,
    this.createdBy,
    this.tags,
    this.updateLogs,
    this.projectBranch,
  });

  factory JobData.fromJson(Map<String, dynamic>? json) {
    if (json == null) return JobData();

    return JobData(
      id: json['id'] as String?,
      title: json['title'] as String?,
      description: json['description'] as String?,
      jobTicketUId: json['jobTicketUId'] as String?,
      project:
          json['project'] != null ? Project.fromJson(json['project']) : null,
      assignees: (json['assignees'] as List<dynamic>?)
              ?.map((e) => Assignee.fromJson(e))
              .toList() ??
          [],
      status: json['status'] != null ? Status.fromJson(json['status']) : null,
      startDate: json['startDate'] as String?,
      dueDate: json['dueDate'] as String?,
      isActive: json['isActive'] as bool?,
      taggingAction: json['taggingAction'],
      attendanceId: json['attendanceId'] as String?,
      nextTaggingAction: json['nextTaggingAction'] as int?,
      createdAt: json['createdAt'] as String?,
      createdBy:
          json['createdBy'] != null ? User.fromJson(json['createdBy']) : null,
      tags: (json['tags'] as List<dynamic>?)
              ?.map((e) => Tag.fromJson(e))
              .toList() ??
          [],
      updateLogs: (json['updateLogs'] as List<dynamic>?)
              ?.map((e) => UpdateLog.fromJson(e))
              .toList() ??
          [],
      projectBranch: json['projectBranch'] != null
          ? ProjectBranch.fromJson(json['projectBranch'])
          : null,
    );
  }
}

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

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

  factory Project.fromJson(Map<String, dynamic>? json) {
    if (json == null) return Project();

    return Project(
      id: json['id'] as String?,
      name: json['name'] as String?,
      shortName: json['shortName'] as String?,
      assignedDate: json['assignedDate'] as String?,
      contactName: json['contactName'] as String?,
      contactPhone: json['contactPhone'] as String?,
      contactEmail: json['contactEmail'] as String?,
    );
  }
}

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

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

  factory Assignee.fromJson(Map<String, dynamic>? json) {
    if (json == null) return Assignee();

    return Assignee(
      id: json['id'] as String?,
      firstName: json['firstName'] as String?,
      lastName: json['lastName'] as String?,
      email: json['email'] as String?,
      photo: json['photo'] as String?,
      jobRoleId: json['jobRoleId'] as String?,
      jobRoleName: json['jobRoleName'] as String?,
    );
  }
}

class ProjectBranch {
  final String? id;
  final String? branchName;
  final String? branchType;

  ProjectBranch({
    this.id,
    this.branchName,
    this.branchType,
  });

  factory ProjectBranch.fromJson(Map<String, dynamic> json) {
    return ProjectBranch(
      id: json['id'],
      branchName: json['branchName'],
      branchType: json['branchType'],
    );
  }
}

class Status {
  final String? id;
  final String? name;
  final String? displayName;
  final int? level;

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

  factory Status.fromJson(Map<String, dynamic>? json) {
    if (json == null) return Status();

    return Status(
      id: json['id'] as String?,
      name: json['name'] as String?,
      displayName: json['displayName'] as String?,
      level: json['level'] as int?,
    );
  }
}

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

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

  factory User.fromJson(Map<String, dynamic>? json) {
    if (json == null) return User();

    return User(
      id: json['id'] as String?,
      firstName: json['firstName'] as String?,
      lastName: json['lastName'] as String?,
      email: json['email'] as String?,
      photo: json['photo'] as String?,
      jobRoleId: json['jobRoleId'] as String?,
      jobRoleName: json['jobRoleName'] as String?,
    );
  }
}

class Tag {
  final String? id;
  final String? name;

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

  factory Tag.fromJson(Map<String, dynamic>? json) {
    if (json == null) return Tag();

    return Tag(
      id: json['id'] as String?,
      name: json['name'] as String?,
    );
  }
}

class UpdateLog {
  final String? id;
  final Status? status;
  final Status? nextStatus;
  final String? comment;
  final String? updatedAt; 
  final User? updatedBy;

  UpdateLog({
    this.id,
    this.status,
    this.nextStatus,
    this.comment,
    this.updatedAt,
    this.updatedBy,
  });

  factory UpdateLog.fromJson(Map<String, dynamic>? json) {
    if (json == null) return UpdateLog();

    return UpdateLog(
      id: json['id'] as String?,
      status: json['status'] != null ? Status.fromJson(json['status']) : null,
      nextStatus: json['nextStatus'] != null
          ? Status.fromJson(json['nextStatus'])
          : null,
      comment: json['comment'] as String?,
      updatedAt: json['updatedAt'] as String?, 
      updatedBy:
          json['updatedBy'] != null ? User.fromJson(json['updatedBy']) : null,
    );
  }
}
