<?php

namespace EasyLinkAutomations\HTTP\Controllers\Triggers;

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

use EasyLinkAutomations\HTTP\Request\Request;
use EasyLinkAutomations\HTTP\Response;

/**
 * Controller for Paymattic trigger endpoints.
 */
final class PaymatticController
{
    /**
     * Return form fields for a specific Paymattic form.
     *
     * Route: paymattic/form-fields
     */
    public function formFields(Request $request): Response
    {
        $formId = (int) $request->get('form_id', 0);
        if ($formId <= 0) {
            return Response::error('form_id is required', 400);
        }

        if (!class_exists('WPPayForm\App\App') && !defined('WPPAYFORM_VERSION')) {
            return Response::error('Paymattic is not active', 400);
        }

        // Paymattic payment fields are standardized across all forms.
        $fields = [
            'form_id'        => 'Form ID',
            'submission_id'  => 'Submission ID',
            'payment_status' => 'Payment Status',
            'payment_total'  => 'Payment Total',
            'currency'       => 'Currency',
            'customer_email' => 'Customer Email',
            'customer_name'  => 'Customer Name',
        ];

        return Response::success(['fields' => $fields]);
    }
}
