const mongoose = require("mongoose");

const patientSchema = new mongoose.Schema(
    {
        patientId: {
            type: String,
            // required: true,
            unique: true,
            uppercase: true,
            trim: true,
        },

        name: {
            type: String,
            required: true,
            trim: true,
            minlength: 3,
            maxlength: 120,
        },

        phone: {
            type: String,
            required: true,
            trim: true,
            // match: [/^[6-9]\d{9}$/, "Invalid Indian mobile number"],
            //   index: true,
        },
        patientType : {
              type : String,
              enum : ["old", "new"],
              default : "new"
        },

        email: {
            type: String,
            trim: true,
            lowercase: true,
            match: [/^\S+@\S+\.\S+$/, "Invalid email address"],
            //   index: true,
            //   sparse: true, //allows multiple null emails
        },

        gender: {
            type: String,
            enum: ["Male", "Female", "Other"],
            // required: true,
        },

        dateOfBirth: {
            type: Date,
            // required: true,
        },

        bloodGroup: {
            type: String,
            enum: ["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"],
        },

        address: {
            type: String,
            trim: true,
            maxlength: 500,
        },
        diagnosis: String,
        status: {
            type: String,
            enum: ["Active", "Inactive"],
            default: "Active",
            //   index: true,
        },
        admissionStatus: {
            type: String,
            enum: [
                "Not Admitted",
                "Admitted",
                "Under Observation",
                "Discharged",
                "Referred",
            ],
            default: "Not Admitted",
        },

        admittedAt: {
            type: Date,
            default: null,
        },

        dischargedAt: {
            type: Date,
            default: null,
        },
        orgId: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "Organization",
            required: true,
            //   index: true,
        },

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

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

        isDeleted: {
            type: Boolean,
            default: false,
            //   index: true,
        },
    },
    {
        timestamps: true, // createdAt, updatedAt
    }
);
module.exports = mongoose.model("Patient", patientSchema);
