<?php
class AuditLog
{
    private $conn;
    private $table_name = "audit_logs";

    public $id;
    public $booking_id;
    public $user_id;
    public $action;
    public $old_status;
    public $new_status;
    public $details;
    public $created_at;

    public function __construct($db)
    {
        $this->conn = $db;
    }

    public function log($booking_id, $action, $old_status = null, $new_status = null, $details = null)
    {
        $query = "INSERT INTO " . $this->table_name . "
                SET
                    booking_id=:booking_id,
                    action=:action,
                    old_status=:old_status,
                    new_status=:new_status,
                    details=:details";

        $stmt = $this->conn->prepare($query);

        $stmt->bindParam(":booking_id", $booking_id);
        $stmt->bindParam(":action", $action);
        $stmt->bindParam(":old_status", $old_status);
        $stmt->bindParam(":new_status", $new_status);
        $stmt->bindParam(":details", $details);

        return $stmt->execute();
    }
}
?>