class NoteListResponseModel {
  final bool success;
  final String message;
  final NotePaginationData data;
  final dynamic errors;
  final int statusCode;
  final DateTime timestamp;

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

  factory NoteListResponseModel.fromJson(Map<String, dynamic> json) {
    return NoteListResponseModel(
      success: json['success'] ?? false,
      message: json['message'] ?? '',
      data: NotePaginationData.fromJson(json['data']),
      errors: json['errors'],
      statusCode: json['statusCode'] ?? 0,
      timestamp: DateTime.parse(json['timestamp']),
    );
  }
}

class NotePaginationData {
  final int currentPage;
  final int pageSize;
  final int totalPages;
  final int totalRecords;
  final List<NoteModel> data;

  NotePaginationData({
    required this.currentPage,
    required this.pageSize,
    required this.totalPages,
    required this.totalRecords,
    required this.data,
  });

  factory NotePaginationData.fromJson(Map<String, dynamic> json) {
    return NotePaginationData(
      currentPage: json['currentPage'] ?? 0,
      pageSize: json['pageSize'] ?? 0,
      totalPages: json['totalPages'] ?? 0,
      totalRecords: json['totalRecords'] ?? 0,
      data: List<NoteModel>.from(
        (json['data'] ?? []).map((x) => NoteModel.fromJson(x)),
      ),
    );
  }
}

class NoteModel {
  final String id;
  final String note;
  final String contactName;
  final String organizationName;
  final DateTime createdAt;
  final UserModel createdBy;
  final DateTime? updatedAt;
  final UserModel? updatedBy;
  final String contactId;
  final bool isActive;

  NoteModel({
    required this.id,
    required this.note,
    required this.contactName,
    required this.organizationName,
    required this.createdAt,
    required this.createdBy,
    this.updatedAt,
    this.updatedBy,
    required this.contactId,
    required this.isActive,
  });
  NoteModel copyWith({String? note, bool? isActive}) => NoteModel(
        id: id,
        note: note ?? this.note,
        contactName: contactName,
        organizationName: organizationName,
        createdAt: createdAt,
        createdBy: createdBy,
        updatedAt: updatedAt,
        updatedBy: updatedBy,
        contactId: contactId,
        isActive: isActive ?? this.isActive,
      );

  factory NoteModel.fromJson(Map<String, dynamic> json) {
    return NoteModel(
      id: json['id'] ?? '',
      note: json['note'] ?? '',
      contactName: json['contactName'] ?? '',
      organizationName: json['organizationName'] ?? '',
      createdAt: DateTime.parse(json['createdAt']),
      createdBy: UserModel.fromJson(json['createdBy']),
      updatedAt: json['updatedAt'] != null
          ? DateTime.tryParse(json['updatedAt'])
          : null,
      updatedBy: json['updatedBy'] != null
          ? UserModel.fromJson(json['updatedBy'])
          : null,
      contactId: json['contactId'] ?? '',
      isActive: json['isActive'] ?? true,
    );
  }
}

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

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

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