<?php

namespace App\Http\Controllers\Member;

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\StoreManualPaymentRequest;
use App\Services\ManualPaymentService;
use App\Models\Subscription;
use Illuminate\Http\Request;

class PaymentController extends Controller
{
    protected $service;

    public function __construct(ManualPaymentService $service)
    {
        $this->service = $service;
    }

    public function show()
    {
        $subscription = auth()->user()->subscriptions()->latest()->first();
        
        if (!$subscription) {
            return redirect()->route('member.plans.index');
        }

        return view('member.payment.show', compact('subscription'));
    }

    public function store(StoreManualPaymentRequest $request)
    {
        $subscription = auth()->user()->subscriptions()->latest()->first();
        
        $this->service->submitProof($subscription, $request->validated(), $request->file('proof'));

        return redirect()->route('dashboard')->with('success', 'Bukti transfer berhasil dikirim. Mohon tunggu verifikasi admin.');
    }
}
