<?php

declare(strict_types=1);

namespace apexl\Io\dto\Relationship\Decorators;

use apexl\Io\interfaces\RelationSqlFragment;
use apexl\Io\interfaces\RelationshipInterface;

/**
 * Renders a raw JOIN fragment, substituting these placeholders in the template:
 *   #REMOTE_TABLE# — relationship's aliased remote table
 *   #LOCAL_TABLE#  — relationship's local table
 */
final readonly class RawJoinTemplate implements RelationSqlFragment
{
    public function __construct(public string $template)
    {
    }

    public function render(RelationshipInterface $relationship): string
    {
        return str_replace(
            ['#REMOTE_TABLE#', '#LOCAL_TABLE#'],
            [$relationship->getAliasedRemoteTable(), $relationship->getLocalTable()],
            $this->template,
        );
    }
}
