<?php

namespace App\Modules\Wallet\Http\Controllers;

use App\Core\Http\Controllers\BaseApiController;
use App\Modules\Wallet\Services\WalletService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

/**
 * المحفظة والمعاملات (API).
 */
class WalletController extends BaseApiController
{
    public function __construct(
        private readonly WalletService $wallet,
    ) {}

    public function show(Request $request): JsonResponse
    {
        $user = $request->user();
        $recentLimit = (int) min(30, max(1, (int) $request->query('recent_limit', 10)));

        return $this->successResponse(
            'تم جلب بيانات المحفظة',
            $this->wallet->walletDashboard($user, $recentLimit)
        );
    }

    public function transactions(Request $request): JsonResponse
    {
        $user = $request->user();
        $perPage = (int) min(50, max(5, (int) $request->query('per_page', 15)));

        return $this->successResponse(
            'تم جلب المعاملات',
            $this->wallet->paginatedTransactions($user, $perPage)
        );
    }
}
