// import mongoose from "mongoose";
const mongoose = require("mongoose");

const visitorSchema = new mongoose.Schema(
  {
    photo: {
      type: String,
    },

    visitorName: {
      type: String,
      required: true,
      trim: true,
    },

    phoneNumber: {
      type: String,
      required: true,
    },

    company: {
      type: String,
      trim: true,
    },

    vehicleNumber: {
      type: String,
      trim: true,
    },

    hostId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      //   required: true
    },

    hostDetails: {
      id: {
        type: mongoose.Schema.Types.ObjectId,
      },
      name: {
        type: String,
        trim: true,
      },
    },

    purpose: {
      type: String,
      trim: true,
    },

    parkingAllocation: {
      type: String,
      enum: ["No Vehicle", "Allocated"],
      default: "No Vehicle",
    },

    timeIn: {
      type: Date,
      default: Date.now,
    },

    exitTime: {
      type: Date,
    },

    hostApproval: {
      type: String,
      enum: ["Pending", "Approved", "Rejected"],
      default: "Pending",
    },

    gateStatus: {
      type: String,
      enum: ["Waiting", "Inside", "Exited"],
      default: "Waiting",
    },

    isDeleted: {
      type: Boolean,
      default: false,
    },

    createdBy: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
    },

    updatedBy: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
    },
  },
  {
    timestamps: { createdAt: true, updatedAt: true },
  },
);

module.exports = mongoose.model("Visitor", visitorSchema);
