<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\LeadStatus;
use Illuminate\Http\JsonResponse;

/**
 * Lookup статусов воронки. Используется в DealsView/KanbanView/DealDetailDrawer
 * как замена статичного `composables/leadStatuses.ts` snapshot'а.
 *
 * Таблица глобальная (нет tenant_id), auth не требуется на MVP. На prod —
 * middleware('auth:sanctum') добавится автоматически без изменений сигнатуры.
 */
class LeadStatusController extends Controller
{
    /** GET /api/lead-statuses */
    public function index(): JsonResponse
    {
        $statuses = LeadStatus::query()
            ->orderBy('sort_order')
            ->orderBy('slug')
            ->get();

        return response()->json([
            'lead_statuses' => $statuses->map(fn (LeadStatus $s) => [
                'slug' => $s->slug,
                'name_ru' => $s->name_ru,
                'is_system' => (bool) $s->is_system,
                'sort_order' => $s->sort_order,
                'color_hex' => $s->color_hex,
                'description' => $s->description,
            ]),
        ]);
    }
}
