<?php

namespace Lucent\Http\Controller;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Lucent\Edge\EdgeService;
use Lucent\Query\Query;

class EdgeController extends Controller
{
    public function __construct(
        public EdgeService $edgeService,
        public Query $query,
    )
    {
    }

    public function insertMany(Request $request)
    {

        $this->edgeService->createMany(
            source: $request->input("source"),
            sourceSchema: $request->input("sourceSchema"),
            targetSchema: $request->input("targetSchema"),
            field: $request->input("field"),
            targets: $request->input("targets"),
        );
        $graph = $this->query
            ->filter(["id" => $request->input("source")])
            ->limit(1)
            ->skip(0)
            ->childrenDepth(2)
            ->childrenLimit(200)
            ->parentsDepth(1)
            ->parentsLimit(200)
            ->run();

        return [
            "graph" => toArray($graph),
        ];
    }

}
