import dotenv from "dotenv";
dotenv.config();
import mongoose from "mongoose";

const VisitSchema = new mongoose.Schema(
  {
    visitBy: {
      type: mongoose.Schema.Types.ObjectId,
      refPath: "visitUserType", // Corrected refPath
      required: true,
    },
    visitUserType: {
      type: String,
      required: true,
      enum: ['SalesCoOrdinator', 'TerritoryManager'],
    },
    addedFor: {
      type: String,
      enum: ["PrincipalDistributor", "RetailDistributor"],
      required: true,
    },
    addedForId: {
      type: mongoose.Schema.Types.ObjectId,
      refPath: "addedFor", // Corrected refPath
      required: true,
    },
    tradename: {
      type: String,
      required: true,
    },
    visitDate: {
      type: Date,
      required: true,
    },
    visitTime: {
      type: String,
      required: true,
    },
    visitpurpose: {
      type: String,
      required: true,
    },
    meetingsummary: {
      type: String,
      required: true,
    },
    followup: {
      type: String,
    },
    nextvisitdate: {
      type: Date,
    },
    documents: [{
      public_id: {
        type: String,
      },
      url: {
        type: String,
      },
    }],
  },
  { timestamps: true }
);

const VisitRDandPD = mongoose.model("Visit", VisitSchema);

export default VisitRDandPD;
