<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\ManualPayment;
use App\Services\PaymentService;
use Illuminate\Http\Request;

class PaymentController extends Controller
{
    protected $service;

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

    public function index()
    {
        $payments = $this->service->getPending();
        return view('admin.payments.index', compact('payments'));
    }

    public function approve(ManualPayment $payment)
    {
        $this->service->approve($payment, auth()->user());
        return back()->with('success', 'Pembayaran disetujui, akun user diaktifkan.');
    }

    public function reject(Request $request, ManualPayment $payment)
    {
        $request->validate(['notes' => 'required|string']);
        $this->service->reject($payment, $request->notes, auth()->user());
        return back()->with('success', 'Pembayaran ditolak.');
    }
}
