import mongoose, { Schema, model } from "mongoose";

const KycSchema = new Schema(
  {
    name: {
      type: String,
      required: true,
      maxlength: [50, "Name cannot be more than 50 characters"],
    },
    email: {
      type: String,
      required: true,
      unique: true,
    },
    trade_name: {
      type: String,
      required: true,
      maxlength: [50, "Trade Name cannot be more than 50 characters"],
    },
    address: {
      type: String,
      required: true,
    },
    state: {
      type: String,
      required: true,
    },
    city: {
      type: String,
      required: true,
    },
    district: {
      type: String,
      required: true,
    },
    pincode: {
      type: String,
      required: true,
    },
    mobile_number: {
      type: String,
      required: true,
    },
    principal_distributer: {
      type: Schema.Types.ObjectId,
      ref: "User",
      // required: true,
    },
    pan_number: {
      type: String,
      required: true,
    },
    pan_img: {
      type: Object,
      // required: true,
    },
    aadhar_number: {
      type: String,
      required: true,
    },
    aadhar_img: {
      type: Object,
      // required: true,
    },
    gst_number: {
      type: String,
      required: true,
    },
    gst_img: {
      type: Object,
      // required: true,
    },
    pesticide_license_img: {
      type: Object,
      // required: true,
    },
    fertilizer_license_img: {
      type: Object,
    },
    selfie_entrance_img: {
      type: Object,
      // required: true,
    },
    status: {
      type: String,
      enum: ["new", "reject", "approved"],
      default: "new",
    },
    rejection_reason: {
      type: String,
    },

    addedBy: {
      type: mongoose.Schema.Types.ObjectId,
      refPath: "userType",
      // required: true,
    },
    userType: {
      type: String,
      // required: true,
      enum: ["SalesCoOrdinator", "TerritoryManager"],
    },
    notes: [
      {
        message: {
          type: String,
          default: "",
        },
        user: {
          type: String,
          enum: [
            "Principal Distributer",
            "Sales Co-ordinator",
            "Territory Manager",
          ],
          // required: true,
        },
        replyDate: {
          type: Date,
          default: Date.now,
        },
      },
    ],
  },
  { timestamps: true }
);
// Pre-save middleware to set 'mapped' based on 'userType'
export const KYC = model("KYC", KycSchema);
