const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const userSchema = new Schema({
    type: {
        type: String,
        enum: ["User", "Technician" , ""],
        default: ""
    },
    fullName: {
        type: String,
        required: true,
    },
    email: {
        type: String,
        required: true,
        unique:true
    },
    password: {
        type: String , default:''
    },
    DOB: {
        type: String, default:''
    },
    phone: {
        type: String, default:''
    },
    profileImage: {
        type: String , default:''
    },
    price: {
        type: Number , default:0
    },
    location: {
        type: {
            type: String,
            enum: ["Point"],
            default: "Point"
        },
        coordinates: {
            type: [Number],
            default: [0, 0]
        },
        locationName: {
            type: String,
            default: ""
        }
    },
    longitude: {
        type: Number, default:0
        // required: true
    },
    latitude: {
        type: Number, default:0
        // required: true
    },
    locationName: {
        type: String , default:''
    },
    service: {
        type: Schema.Types.ObjectId,
        ref: "Service" , default: null
    },
    workingHours: {
        startTime: {
            type: String, default: ""
        },
        endTime: {
            type: String , default: ""
        }
    },
    ss: {
        type: String , default: ""
    },
    portfolio: {
        type:[String],
        default:[]
    },
    pestControlLicense:{
        type:[String],
        default:[]
    },
    favouriteBy: {
        type: [Schema.Types.ObjectId],
        ref: "User",
        default: []
    },
    isDeleted: {
        type: Boolean,
        default: false
    },
    avgRating: {
        type: String , default: "0"
    },
    totalReviews: {
        type: String , default: "0"
    },
    googleId: { type: String, default: null},
    isGoogleUser: { type: Boolean, default: false },
    stripeCustomerId: { type: String, default: null }, 
});

userSchema.index({ location: "2dsphere" });

const userModel = mongoose.model("User", userSchema);
module.exports = userModel;