<?php

namespace App\Http\Controllers\Admin;

use App\Models\BusinessPayment;
use Illuminate\Http\Request;
use Inertia\Inertia;

class AdminBusinessPaymentController extends Controller
{
    public function index()
    {
        $payments = BusinessPayment::with('business')->latest('date')->get();

        return Inertia::render('Admin/Payments/Index', [
            'payments' => $payments,
        ]);
    }

    public function verify(BusinessPayment $payment)
    {
        $payment->update(['status' => 'verified']);

        // If payment is for subscription, update business plan
        if ($payment->amount >= 1000) { // assume basic is 1000
            $business = $payment->business;
            $business->update([
                'plan_type' => 'basic',
                'plan_expiry_date' => today()->addMonth(),
                'plan_status' => 'active',
            ]);
            $business->subscriptions()->create([
                'plan_type' => 'basic',
                'expiry_date' => today()->addMonth(),
                'status' => 'active',
            ]);
        }

        return redirect()->back();
    }
}