<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Payment;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class PaymentController extends Controller
{
    public function history(Request $request): JsonResponse
    {
        $user = $request->user();

        abort_unless($user->role === 'client', 403);

        $payments = Payment::query()
            ->where('client_id', $user->id)
            ->with(['mission:id,title', 'liner:id,name', 'paymentMethod:id,label,provider,type'])
            ->latest()
            ->paginate(20);

        return response()->json(['data' => $payments]);
    }
}
