import mongoose from "mongoose";

const auditLogSchema = new mongoose.Schema(

    {

        userId: {

            type: mongoose.Schema.Types.ObjectId,
            ref: "User"

        },

        module: {

            type: String,
            required: true,
            enum: [

                "User",

                "Role",

                "FuelRequest",

                "Approval",

                "ExternalInvoice",

                "LPG",

                "PumpReading",

                "FuelPump",

                "FuelPrice",

                "FuelType",

                "VehicleConfig",

                "VehicleAssignment",

                "Dashboard",

                "Report",

                "Authentication"
            ]

        },

        action: {

            type: String,
            required: true,
            enum: [

                "CREATE",

                "UPDATE",

                "DELETE",

                "APPROVE",

                "REJECT",

                "LOGIN",

                "LOGOUT",

                "CLOSE"

            ]

        },

        recordId: {

            type: mongoose.Schema.Types.ObjectId

        },

        description: {

            type: String,

            required: true

        },

        ipAddress: {

            type: String

        },

        status: {

            type: String,

            required: true,

            enum: [

                "EXITOSO",

                "FALLIDO"

            ],

            default: "EXITOSO"

        }

    },

    {

        timestamps: true,

        versionKey: false

    }

);

export default mongoose.model("AuditLog",auditLogSchema);