<?php

namespace App\Http\Controllers;

use App\Models\BusinessPayment;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Inertia\Inertia;

class BusinessPaymentController extends Controller
{
    public function index()
    {
        $payments = Auth::guard('business')->user()->payments()->latest('date')->get();

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

    public function create()
    {
        return Inertia::render('Business/Payments/Create');
    }

    public function store(Request $request)
    {
        $request->validate([
            'amount' => 'required|numeric|min:1',
            'payment_method' => 'required|in:cash,esewa,khalti',
        ]);

        Auth::guard('business')->user()->payments()->create([
            'amount' => $request->amount,
            'payment_method' => $request->payment_method,
            'status' => 'pending',
            'date' => today(),
        ]);

        return redirect()->route('business.payments.index');
    }
}