import mongoose, { Schema, Document } from 'mongoose'; import { ChatMessage, Conversation, CreateEventDTO } from '@caldav/shared'; export interface ChatMessageDocument extends Omit, Document {} export interface ConversationDocument extends Omit, Document {} const ProposedEventSchema = new Schema( { title: { type: String, required: true }, description: { type: String }, startTime: { type: Date, required: true }, endTime: { type: Date, required: true }, note: { type: String }, isRecurring: { type: Boolean }, recurrenceRule: { type: String }, }, { _id: false } ); const ChatMessageSchema = new Schema( { conversationId: { type: String, required: true, }, sender: { type: String, enum: ['user', 'assistant'], required: true, }, content: { type: String, required: true, }, proposedEvent: { type: ProposedEventSchema, }, }, { timestamps: true, toJSON: { transform: (_, ret: Record) => { ret.id = String(ret._id); delete ret._id; delete ret.__v; return ret; }, }, } ); const ConversationSchema = new Schema( { userId: { type: String, required: true, index: true, }, }, { timestamps: true, toJSON: { transform: (_, ret: Record) => { ret.id = String(ret._id); delete ret._id; delete ret.__v; return ret; }, }, } ); export const ChatMessageModel = mongoose.model('ChatMessage', ChatMessageSchema); export const ConversationModel = mongoose.model('Conversation', ConversationSchema);