<?php

declare(strict_types=1);

namespace Apexl\Io\Dtos\Relationship\Decorators;

use Apexl\Io\Interfaces\RelationshipInterface;
use Apexl\Io\Interfaces\RelationSqlFragment;

/**
 * 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,
        );
    }
}
