import { CaldavConfig } from "@calchat/shared";
import mongoose, { Document, Schema } from "mongoose";

export interface CaldavConfigDocument extends CaldavConfig, Document {
  toJSON(): CaldavConfig;
}

const CaldavConfigSchema = new Schema<CaldavConfigDocument>(
  {
    userId: { type: String, required: true, index: true },
    serverUrl: { type: String, required: true },
    username: { type: String, required: true },
    password: { type: String, required: true },
    syncIntervalSeconds: { type: Number },
  },
  { _id: false },
);

export const CaldavConfigModel = mongoose.model<CaldavConfigDocument>(
  "CaldavConfig",
  CaldavConfigSchema,
);
