<?php

namespace App\Services;

use App\Exceptions\SchoolYear\SchoolYearWriteConflictException;
use App\Support\SchoolYear\SchoolYearContext;

final class SchoolYearWriteGuard
{
    public function assertWritable(
        SchoolYearContext $context,
        bool $allowDraftForAdmin = false,
        bool $isAdmin = false
    ): void {
        if (strtolower($context->status()) === 'active') {
            return;
        }

        if (strtolower($context->status()) === 'draft' && $allowDraftForAdmin && $isAdmin) {
            return;
        }

        throw new SchoolYearWriteConflictException('The selected school year is read-only.');
    }
}
