<?php

declare(strict_types=1);

namespace App\Scolarite\Domain\Service;

use App\Administration\Domain\Model\SchoolClass\ClassId;
use App\Scolarite\Domain\Model\Homework\Homework;
use DateTimeImmutable;

final readonly class HomeworkDuplicator
{
    /**
     * @param array<ClassId>           $targetClassIds
     * @param array<DateTimeImmutable> $dueDates       Dates indexées par position (même ordre que $targetClassIds)
     *
     * @return array<Homework>
     */
    public function dupliquer(
        Homework $source,
        array $targetClassIds,
        array $dueDates,
        DateTimeImmutable $now,
    ): array {
        $duplicates = [];

        foreach ($targetClassIds as $index => $classId) {
            $dueDate = $dueDates[$index] ?? $source->dueDate;

            $duplicates[] = Homework::creer(
                tenantId: $source->tenantId,
                classId: $classId,
                subjectId: $source->subjectId,
                teacherId: $source->teacherId,
                title: $source->title,
                description: $source->description,
                dueDate: $dueDate,
                now: $now,
            );
        }

        return $duplicates;
    }
}
