<?php

namespace Lucent\Http\Controller\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Lucent\Edge\EdgeService;
use Lucent\LucentException;
use function Lucent\Response\fail;
use function Lucent\Response\ok;

class EdgeController extends Controller
{

    public function create(Request $request): Response
    {
        try {
            $edge = EdgeService::create(
                source: $request->input("source"),
                target: $request->input("target"),
                sourceSchema: $request->input("sourceSchema"),
                targetSchema: $request->input("targetSchema"),
                field: $request->input("field"),
                rank: $request->input("rank") ?? "",
            );
        } catch (LucentException $th) {
            return fail($th);
        }


        return ok([
            "edge" => $edge,
        ]);
    }

}
