<?php

namespace DhlPolskaVendor\Octolize\Blocks\PickupPoint;

use WC_Shipping_Method;
class PickupPointValidatorForShippingMethod implements PickupPointValidator
{
    private string $shipping_method_id;
    private string $setting_key;
    private string $setting_value;
    private string $error_message;
    public function __construct(string $shipping_method_id, string $setting_key, string $setting_value, string $error_message)
    {
        $this->shipping_method_id = $shipping_method_id;
        $this->setting_key = $setting_key;
        $this->setting_value = $setting_value;
        $this->error_message = $error_message;
    }
    public function validate(string $value, WC_Shipping_Method $shipping_method): void
    {
        // phpcs:ignore
        if ($shipping_method->id === $this->shipping_method_id && $shipping_method->get_option($this->setting_key) === $this->setting_value && empty($value)) {
            throw new SelectPickupPointException($this->error_message);
        }
    }
}
