<?php

namespace App\Http\Controllers\Api\V1\Currency;

use App\Models\Currency;
use App\Support\ApiResponse;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;

final class CurrencyIndexController extends Controller
{
    public function __invoke(): JsonResponse
    {
        $items = Currency::query()
            ->where('is_enabled', true)
            ->orderByDesc('is_bettable')
            ->orderBy('code')
            ->get()
            ->map(fn (Currency $currency): array => [
                'code' => $currency->code,
                'name' => $currency->name,
                'decimal_places' => (int) $currency->decimal_places,
                'is_bettable' => (bool) $currency->is_bettable,
            ])
            ->all();

        return ApiResponse::success(['items' => $items]);
    }
}
