<?php

namespace Formatrica\Capability\Rules;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use Formatrica\Capability\Capabilities;
use Formatrica\Capability\Premium_Config_Rule_Interface;

/**
 * HARD save-path gate for payments (payments.basic).
 *
 * Unlike the preserve-existing rules, this ignores prior state entirely — there
 * is NO grandfathering. `options.payments.enabled` IS feature activation; letting
 * it round-trip on a Free/expired install (even if the stored form had it on)
 * would let a crafted save collect money the platform can't legitimately process.
 * It forces `enabled = false` unconditionally and preserves every other payments.*
 * key so a renewal restores a working config. Mirrors com_nxpeasyforms
 * PaymentsHardGateRule.
 */
final class Payments_Hard_Gate_Rule implements Premium_Config_Rule_Interface
{
    public function capability(): string
    {
        return Capabilities::PAYMENTS_BASIC;
    }

    public function enforce(array &$config, array $existing): array
    {
        if (empty($config['options']['payments']['enabled'])) {
            return [];
        }

        $config['options']['payments']['enabled'] = false;

        return [[
            'key'        => 'options.payments.enabled',
            'reason'     => __('Payments are a Pro feature; the toggle was reverted.', 'formatrica'),
            'capability' => $this->capability(),
            'feature'    => 'payments',
        ]];
    }
}
