<?php

namespace App\Http\Controllers;

use App\Services\MapDataService;
use Illuminate\Http\Request;
use Inertia\Inertia;

class MapController extends Controller
{
    public function __construct(
        private MapDataService $mapDataService
    ) {}

    public function index()
    {
        $mapData = $this->mapDataService->getStrategyMap();

        return Inertia::render('Map/MetroMap', [
            'mapData'     => $mapData,
            'users'       => \App\Models\User::select('id', 'name')->get(),
            'speerpunten' => \App\Models\Speerpunt::select('id', 'naam', 'thema_id')->with('thema:id,naam')->get(),
        ]);
    }

    public function project(int $projectId)
    {
        $mapData = $this->mapDataService->getProjectMap($projectId);

        return Inertia::render('Map/MetroMap', [
            'mapData'     => $mapData,
            'users'       => \App\Models\User::select('id', 'name')->get(),
            'speerpunten' => \App\Models\Speerpunt::select('id', 'naam', 'thema_id')->with('thema:id,naam')->get(),
        ]);
    }

    public function apiStrategy(Request $request)
    {
        return response()->json($this->mapDataService->getStrategyMap());
    }

    public function apiProject(int $projectId)
    {
        return response()->json($this->mapDataService->getProjectMap($projectId));
    }

    public function apiNodeChildren(string $type, int $id)
    {
        return response()->json($this->mapDataService->getNodeChildren($type, $id));
    }
}
