import 'package:didvan/models/ai/bot_assistants_model.dart'; import 'package:didvan/models/ai/bots_model.dart'; import 'package:didvan/models/ai/files_model.dart'; class ChatsModel { int? id; int? userId; int? botId; String? title; String? placeholder; String? createdAt; String? updatedAt; String? responseType; BotsModel? bot; BotAssistants? userBot; List? prompts; bool? isEditing; String? assistantsName; ChatsModel( {this.id, this.userId, this.botId, this.title, this.placeholder, this.createdAt, this.updatedAt, this.bot, this.prompts, this.isEditing = false, this.assistantsName, this.responseType, this.userBot}); ChatsModel.fromJson(Map json) { id = json['id']; userId = json['userId']; botId = json['botId']; title = json['title']; placeholder = json['placeholder']; createdAt = json['createdAt']; updatedAt = json['updatedAt']; responseType = json['responseType']; userBot = json['userBot'] != null ? BotAssistants.fromJson(json['userBot']) : null; bot = json['bot'] != null ? BotsModel.fromJson(json['bot']) : userBot?.bot?.copyWith( id: userBot?.id, image: userBot?.image, ); if (userBot != null) { assistantsName = userBot!.name; } if (json['prompts'] != null) { prompts = []; json['prompts'].forEach((v) { prompts!.add(Prompts.fromJson(v)); }); } } Map toJson() { final Map data = {}; data['id'] = id; data['userId'] = userId; data['botId'] = botId; data['title'] = title; data['placeholder'] = placeholder; data['createdAt'] = createdAt; data['updatedAt'] = updatedAt; data['responseType'] = responseType; if (bot != null) { data['bot'] = bot!.toJson(); } if (prompts != null) { data['prompts'] = prompts!.map((v) => v.toJson()).toList(); } return data; } ChatsModel copyWith( {int? id, int? userId, int? botId, String? title, String? placeholder, String? createdAt, String? updatedAt, BotsModel? bot, List? prompts, bool? isEditing}) { return ChatsModel( id: id ?? this.id, userId: userId ?? this.userId, botId: botId ?? this.botId, title: title ?? this.title, placeholder: placeholder ?? this.placeholder, bot: bot ?? this.bot, createdAt: createdAt ?? this.createdAt, updatedAt: updatedAt ?? this.updatedAt, prompts: prompts ?? this.prompts, isEditing: isEditing ?? this.isEditing, ); } } class Prompts { int? id; int? chatId; String? text; String? file; String? fileName; String? role; String? createdAt; bool? finished; bool? error; bool? audio; int? duration; FilesModel? fileLocal; Prompts( {this.id, this.chatId, this.text, this.file, this.fileName, this.role, this.createdAt, this.finished, this.error, this.audio, this.fileLocal, this.duration}); Prompts.fromJson(Map json) { id = json['id']; chatId = json['chatId']; text = json['text']; file = json['file']; fileName = json['fileName']; role = json['role']; createdAt = json['createdAt']; audio = json['audio']; duration = json['duration']; } Map toJson() { final Map data = {}; data['id'] = id; data['chatId'] = chatId; data['text'] = text; data['file'] = file; data['fileName'] = fileName; data['role'] = role; data['createdAt'] = createdAt; data['audio'] = audio; data['duration'] = duration; return data; } Prompts copyWith({ int? id, int? chatId, String? text, String? file, String? fileName, FilesModel? fileLocal, String? role, String? createdAt, bool? finished, bool? error, bool? audio, int? duration, }) { return Prompts( id: id ?? this.id, chatId: chatId ?? this.chatId, text: text ?? this.text, file: file ?? this.file, fileName: fileName ?? this.fileName, fileLocal: fileLocal ?? this.fileLocal, role: role ?? this.role, createdAt: createdAt ?? this.createdAt, finished: finished ?? this.finished, error: error ?? this.error, audio: audio ?? this.audio, duration: duration ?? this.duration, ); } }