<?php namespace Lucent\Edge;

use Lucent\LucentException;

class EdgeService
{
    public function __construct(public EdgeRepo $edgeRepo)
    {
    }

    /**
     * @throws LucentException
     */
    public function create(
        string $source,
        string $target,
        string $sourceSchema,
        string $targetSchema,
        string $field,
        string $rank,
    ): Edge
    {


        $edge = new Edge(

            source: $source,
            target: $target,
            sourceSchema: $sourceSchema,
            targetSchema: $targetSchema,
            field: $field,
            rank: $rank,
        );
        $this->edgeRepo->insert($edge);
        return $edge;
    }

    public function update(string $from, EdgeCollection $edges): void
    {
        $this->edgeRepo->update($from, $edges);
    }

    public function findAll(): EdgeCollection
    {
        return $this->edgeRepo->findAll();
    }

    public function remove(Edge $edge): void
    {
        $this->edgeRepo->remove($edge);
    }

}
