<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Transaction;
use App\Models\Wallet;
use App\Models\Ride;

class TransactionController extends Controller
{
    /**
     * List all system transactions.
     */
    public function index()
    {
        $transactions = Transaction::with('wallet.user')->orderBy('created_at', 'desc')->paginate(30);
        $totalVolume = Transaction::sum('amount');
        $commissionEarned = Ride::where('status', 'completed')->sum('fare') * 0.1; // 10% mock commission

        return view('admin.transactions.index', compact('transactions', 'totalVolume', 'commissionEarned'));
    }

    /**
     * Platform settings (Commission, etc.)
     */
    public function settings()
    {
        return view('admin.settings');
    }

    /**
     * Update global commission.
     */
    public function updateSettings(Request $request)
    {
        // For now, this could save to a 'settings' table or env
        return back()->with('success', 'Platform settings updated!');
    }
}
