<?php

namespace App\Http\Controllers;

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

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

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

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

    public function store(Request $request)
    {
        $request->validate([
            'amount' => 'required|numeric|min:1',
            'payment_method' => 'required|in:cash,esewa,khalti',
            'plan_type' => 'required|in:basic,premium',
            'reference' => 'nullable|string|max:255',
        ]);

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

        return redirect()->route('shop.payments.index')->with('success', 'Payment request submitted. Admin will verify it soon.');
    }
}
