<?php

declare(strict_types=1);

namespace App\Administration\Infrastructure\Persistence\InMemory;

use App\Administration\Domain\Model\Import\KnownImportFormat;
use App\Administration\Domain\Model\Import\StudentImportField;
use App\Administration\Domain\Repository\SavedColumnMappingRepository;
use App\Shared\Domain\Tenant\TenantId;
use Override;

final class InMemorySavedColumnMappingRepository implements SavedColumnMappingRepository
{
    /** @var array<string, array<string, StudentImportField>> */
    private array $store = [];

    #[Override]
    public function save(TenantId $tenantId, KnownImportFormat $format, array $mapping): void
    {
        $this->store[$this->key($tenantId, $format)] = $mapping;
    }

    #[Override]
    public function findByTenantAndFormat(TenantId $tenantId, KnownImportFormat $format): ?array
    {
        return $this->store[$this->key($tenantId, $format)] ?? null;
    }

    private function key(TenantId $tenantId, KnownImportFormat $format): string
    {
        return (string) $tenantId . ':' . $format->value;
    }
}
