import mongoose from "mongoose";

const fuelRequestSchema = new mongoose.Schema({

    requestNumber:{
        type:String,
        required:true,
        unique:true
    },

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

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

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

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

    fuelPumpId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"FuelPump"
    },

    fuelTypeId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"FuelType"
    },

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

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

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

    pricePerGallon:{
        type:Number,
        default:0
    },

    totalAmount:{
        type:Number,
        default:0
    },

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

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

    distanceTraveled:{
        type:Number,
        default:0
    },

    pumpReading:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"PumpReading",
    },

    pumpDifference:{
        type:Number,
        default:0
    },

    comments:{
        type:String
    },

    odometerWorking:{
        type:Boolean,
        default:true

    },

    status:{
        type:String,
        enum:[
            "PENDIENTE",
            "APROBADO",
            "RECHAZADO",
        ],

        default:"PENDIENTE"
    }
},

{
    timestamps:true
}

);

export default mongoose.model("FuelRequest", fuelRequestSchema);