<?php

namespace App\Http\Controllers;

use App\Models\Order;
use App\Models\DownloadLog;
use Illuminate\Http\Request;

class DownloadController extends Controller
{
    public function process(Request $request, Order $order)
    {
        // CheckOrderPaid middleware ensures order belongs to user and is paid
        
        // Log the download
        DownloadLog::create([
            'user_id' => auth()->id(),
            'order_id' => $order->id,
            'product_id' => $order->product_id,
            'ip_address' => $request->ip(),
        ]);

        return redirect()->away($order->product->drive_link);
    }
}
