<?php

namespace DhlPolskaVendor\Octolize\Blocks\PickupPoint;

use WC_Shipping_Method;
class PickupPointValidatorForFsIntegration implements PickupPointValidator
{
    private string $fs_integration;
    private string $setting_key;
    private string $setting_value;
    private string $error_message;
    public function __construct(string $fs_integration, string $setting_key, string $setting_value, string $error_message)
    {
        $this->fs_integration = $fs_integration;
        $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
    {
        if ($this->should_check_field($shipping_method) && empty($value)) {
            throw new SelectPickupPointException($this->error_message);
        }
    }
    protected function should_check_field(WC_Shipping_Method $shipping_method): bool
    {
        return $shipping_method->id === 'flexible_shipping_single' && $shipping_method->get_instance_option('method_integration') === $this->fs_integration && $shipping_method->get_instance_option($this->setting_key) === $this->setting_value;
    }
}
