import mongoose from "mongoose";

const anomalySchema = new mongoose.Schema({

    vehicleId:{
        type:Number,
        required:true
    },

    employeeId:{
        type:Number
    },

    fuelRequestId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"FuelRequest"
    },

    externalInvoiceId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"ExternalInvoice"
    },

    lpg:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"LPG"
    },

    anomalyType:{
        type:String,
        required:true,
        enum:[
            "RENDIMIENTO BAJO",
            "CONSUMO ELEVADO",
            "KILOMETRAJE FUERA DE RANGO",
            "ODOMETRO EN MAL ESTADO",
            "VEHICULO NO ASIGNADO",
            "FUGA DE COMBUSTIBLE",
            "DIFERENCIA EN BOMBA",
            "OTRO"
        ]
    },

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

    detectedBy:{
        type:String,
        required:true,
        enum:[
            "SISTEMA",
            "USUARIO"
        ]
    },

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

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

    resolvedDate:{
        type:Date
    },

    status:{
        type:String,
        required:true,
        enum:[
            "ABIERTA",
            "EN PROCESO",
            "CERRADA"
        ],
        default:"ABIERTA"
    },

    comments:{
        type:String
    }

},
    {
        timestamps:true
    }

);

export default mongoose.model("Anomaly", anomalySchema);