<?php

declare(strict_types=1);

namespace App\Administration\Infrastructure\Persistence\InMemory;

use App\Administration\Domain\Model\AcademicYear\PeriodConfiguration;
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
use App\Administration\Domain\Repository\PeriodConfigurationRepository;
use App\Shared\Domain\Tenant\TenantId;

final class InMemoryPeriodConfigurationRepository implements PeriodConfigurationRepository
{
    /** @var array<string, PeriodConfiguration> */
    private array $configurations = [];

    public function save(TenantId $tenantId, AcademicYearId $academicYearId, PeriodConfiguration $configuration): void
    {
        $this->configurations[$this->key($tenantId, $academicYearId)] = $configuration;
    }

    public function findByAcademicYear(TenantId $tenantId, AcademicYearId $academicYearId): ?PeriodConfiguration
    {
        return $this->configurations[$this->key($tenantId, $academicYearId)] ?? null;
    }

    private function key(TenantId $tenantId, AcademicYearId $academicYearId): string
    {
        return (string) $tenantId . ':' . (string) $academicYearId;
    }
}
