<?php
/**
 * Swish payment provider (preparation — guest checkout not yet active).
 *
 * @package Maca_Menu_List
 */

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

require_once MACA_MENULIST_PLUGIN_DIR . 'includes/payments/class-payment-provider.php';

/**
 * Swish Handel / partner API preparation.
 */
class Maca_Menulist_Payment_Provider_Swish extends Maca_Menulist_Payment_Provider {

    /**
     * @return string
     */
    public function get_id() {
        return 'swish';
    }

    /**
     * @return string
     */
    public function get_label() {
        return __('Swish', 'maca-restu-pro');
    }

    /**
     * @return string
     */
    public function get_description() {
        return __(
            'Direct Swish for merchants (Swish Handel). Many restaurants enable Swish via Stripe instead — see the setup guide.',
            'maca-restu-pro'
        );
    }

    /**
     * @return array<int, string>
     */
    public function get_setting_keys() {
        return array(
            'test_mode',
            'merchant_id',
            'callback_url_verified',
        );
    }

    /**
     * @return array<int, string>
     */
    public function get_required_setting_keys() {
        return array('merchant_id');
    }

    /**
     * @param array<string, string> $values Values.
     * @return true|WP_Error
     */
    public function validate_settings($values) {
        $merchant = isset($values['merchant_id']) ? preg_replace('/\s+/', '', $values['merchant_id']) : '';
        if ($merchant !== '' && !preg_match('/^[0-9]{10}$/', $merchant)) {
            return new WP_Error(
                'maca_swish_merchant',
                __('Swish merchant number must be 10 digits (your Swish Handel number).', 'maca-restu-pro')
            );
        }

        return true;
    }

    /**
     * @return array<int, array<string, mixed>>
     */
    public function get_admin_fields() {
        return array(
            array(
                'key' => 'test_mode',
                'type' => 'checkbox',
                'label' => __('Test / sandbox', 'maca-restu-pro'),
                'description' => __('Enable while using Swish test credentials from your bank or technical partner.', 'maca-restu-pro'),
            ),
            array(
                'key' => 'merchant_id',
                'type' => 'text',
                'label' => __('Swish number (Handel)', 'maca-restu-pro'),
                'description' => __('10-digit Swish Handel number for your business, not a private Swish number.', 'maca-restu-pro'),
                'autocomplete' => 'off',
            ),
            array(
                'key' => 'callback_url_verified',
                'type' => 'checkbox',
                'label' => __('Callback URL registered with bank/partner', 'maca-restu-pro'),
                'description' => __(
                    'Check when your bank or Swish technical partner has approved the webhook URL shown in the setup guide.',
                    'maca-restu-pro'
                ),
            ),
        );
    }
}
