171 lines
3.9 KiB
Dart
171 lines
3.9 KiB
Dart
import 'package:didvan/models/ai/bots_model.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
class ChatsModel {
|
|
int? id;
|
|
int? userId;
|
|
int? botId;
|
|
String? title;
|
|
String? placeholder;
|
|
String? createdAt;
|
|
String? updatedAt;
|
|
BotsModel? bot;
|
|
List<Prompts>? prompts;
|
|
bool? isEditing;
|
|
|
|
ChatsModel({
|
|
this.id,
|
|
this.userId,
|
|
this.botId,
|
|
this.title,
|
|
this.placeholder,
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
this.bot,
|
|
this.prompts,
|
|
this.isEditing = false,
|
|
});
|
|
|
|
ChatsModel.fromJson(Map<String, dynamic> json) {
|
|
id = json['id'];
|
|
userId = json['userId'];
|
|
botId = json['botId'];
|
|
title = json['title'];
|
|
placeholder = json['placeholder'];
|
|
createdAt = json['createdAt'];
|
|
updatedAt = json['updatedAt'];
|
|
bot = json['bot'] != null ? BotsModel.fromJson(json['bot']) : null;
|
|
if (json['prompts'] != null) {
|
|
prompts = <Prompts>[];
|
|
json['prompts'].forEach((v) {
|
|
prompts!.add(Prompts.fromJson(v));
|
|
});
|
|
}
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
final Map<String, dynamic> data = <String, dynamic>{};
|
|
data['id'] = id;
|
|
data['userId'] = userId;
|
|
data['botId'] = botId;
|
|
data['title'] = title;
|
|
data['placeholder'] = placeholder;
|
|
data['createdAt'] = createdAt;
|
|
data['updatedAt'] = updatedAt;
|
|
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>? 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;
|
|
|
|
Prompts(
|
|
{this.id,
|
|
this.chatId,
|
|
this.text,
|
|
this.file,
|
|
this.fileName,
|
|
this.role,
|
|
this.createdAt,
|
|
this.finished,
|
|
this.error,
|
|
this.audio,
|
|
this.duration});
|
|
|
|
Prompts.fromJson(Map<String, dynamic> 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<String, dynamic> toJson() {
|
|
final Map<String, dynamic> data = <String, dynamic>{};
|
|
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,
|
|
XFile? 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,
|
|
role: role ?? this.role,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
finished: finished ?? this.finished,
|
|
error: error ?? this.error,
|
|
audio: audio ?? this.audio,
|
|
duration: duration ?? this.duration,
|
|
);
|
|
}
|
|
}
|