
class JobAttendanceResponse {
  final bool success;
  final String message;
  final List<JobAttendanceData>? data;
  final dynamic errors;
  final int statusCode;
  final DateTime timestamp;

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

  factory JobAttendanceResponse.fromJson(Map<String, dynamic> json) {
    return JobAttendanceResponse(
      success: json['success'] ?? false,
      message: json['message'] ?? '',
      data: (json['data'] as List<dynamic>?)
          ?.map((e) => JobAttendanceData.fromJson(e))
          .toList(),
      errors: json['errors'],
      statusCode: json['statusCode'] ?? 0,
      timestamp: DateTime.parse(json['timestamp']),
    );
  }

  Map<String, dynamic> toJson() => {
        'success': success,
        'message': message,
        'data': data?.map((e) => e.toJson()).toList(),
        'errors': errors,
        'statusCode': statusCode,
        'timestamp': timestamp.toIso8601String(),
      };
}

class JobAttendanceData {
  final String id;
  final JobTicket jobTicket;
  final Document? document;
  final String? latitude;
  final String? longitude;
  final int action;
  final String? comment;
  final Employee employee;
  final DateTime markedTime;
  final DateTime markedAt;

  JobAttendanceData({
    required this.id,
    required this.jobTicket,
    this.document,
    this.latitude,
    this.longitude,
    required this.action,
    this.comment,
    required this.employee,
    required this.markedTime,
    required this.markedAt,
  });

  factory JobAttendanceData.fromJson(Map<String, dynamic> json) {
    return JobAttendanceData(
      id: json['id'] ?? '',
      jobTicket: JobTicket.fromJson(json['jobTicket']),
      document: json['document'] != null
          ? Document.fromJson(json['document'])
          : null,
      latitude: json['latitude'],
      longitude: json['longitude'],
      action: json['action'] ?? 0,
      comment: json['comment'],
      employee: Employee.fromJson(json['employee']),
      markedTime: DateTime.parse(json['markedTIme']),
      markedAt: DateTime.parse(json['markedAt']),
    );
  }

  Map<String, dynamic> toJson() => {
        'id': id,
        'jobTicket': jobTicket.toJson(),
        'document': document?.toJson(),
        'latitude': latitude,
        'longitude': longitude,
        'action': action,
        'comment': comment,
        'employee': employee.toJson(),
        'markedTIme': markedTime.toIso8601String(),
        'markedAt': markedAt.toIso8601String(),
      };
}

class JobTicket {
  final String id;
  final String title;
  final String description;
  final String jobTicketUId;
  final String statusName;

  JobTicket({
    required this.id,
    required this.title,
    required this.description,
    required this.jobTicketUId,
    required this.statusName,
  });

  factory JobTicket.fromJson(Map<String, dynamic> json) {
    return JobTicket(
      id: json['id'] ?? '',
      title: json['title'] ?? '',
      description: json['description'] ?? '',
      jobTicketUId: json['jobTicketUId'] ?? '',
      statusName: json['statusName'] ?? '',
    );
  }

  Map<String, dynamic> toJson() => {
        'id': id,
        'title': title,
        'description': description,
        'jobTicketUId': jobTicketUId,
        'statusName': statusName,
      };
}

class Document {
  final String documentId;
  final String fileName;
  final String contentType;
  final String preSignedUrl;
  final String thumbPreSignedUrl;

  Document({
    required this.documentId,
    required this.fileName,
    required this.contentType,
    required this.preSignedUrl,
    required this.thumbPreSignedUrl,
  });

  factory Document.fromJson(Map<String, dynamic> json) {
    return Document(
      documentId: json['documentId'] ?? '',
      fileName: json['fileName'] ?? '',
      contentType: json['contentType'] ?? '',
      preSignedUrl: json['preSignedUrl'] ?? '',
      thumbPreSignedUrl: json['thumbPreSignedUrl'] ?? '',
    );
  }

  Map<String, dynamic> toJson() => {
        'documentId': documentId,
        'fileName': fileName,
        'contentType': contentType,
        'preSignedUrl': preSignedUrl,
        'thumbPreSignedUrl': thumbPreSignedUrl,
      };
}

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

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

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

  Map<String, dynamic> toJson() => {
        'id': id,
        'firstName': firstName,
        'lastName': lastName,
        'email': email,
        'photo': photo,
        'jobRoleId': jobRoleId,
        'jobRoleName': jobRoleName,
      };
}
