<?php

declare(strict_types=1);

namespace App\Business\Product;

use App\Models\DberpProductSku;
use Illuminate\Validation\ValidationException;

final class ProductSkuOperationalGuard
{
    public static function assertEnabledForPurchase(DberpProductSku $sku): void
    {
        self::assertEnabled($sku, 'purchase');
    }

    public static function assertEnabledForSale(DberpProductSku $sku): void
    {
        self::assertEnabled($sku, 'sale');
    }

    private static function assertEnabled(DberpProductSku $sku, string $context): void
    {
        if (! $sku->is_enabled) {
            throw ValidationException::withMessages([
                'product_sku_id' => __('dberp.errors.product_sku_disabled_'.$context),
            ]);
        }
    }
}
