<?php

declare(strict_types=1);

namespace MauticPlugin\DealFlowBundle\Integration;

use Mautic\PluginBundle\Integration\AbstractIntegration;

class DealFlowIntegration extends AbstractIntegration
{
    public function getName(): string
    {
        return 'DealFlow';
    }

    public function getDisplayName(): string
    {
        return 'Deal Flow';
    }

    public function getAuthenticationType(): string
    {
        return 'none';
    }

    /**
     * @return array<string, string>
     */
    public function getRequiredKeyFields(): array
    {
        return [
            'license_key' => 'mautic.dealflow.integration.license_key',
        ];
    }

    /**
     * @return list<string>
     */
    public function getSecretKeys(): array
    {
        return ['license_key'];
    }

    /**
     * Show license status note in the Details tab.
     *
     * @param mixed $section
     *
     * @return mixed
     */
    public function getFormNotes($section)
    {
        if ('authorization' === $section) {
            $entity = $this->getIntegrationSettings();
            $featureSettings = $entity->getFeatureSettings() ?? [];
            $status = $featureSettings['license_status'] ?? 'not_configured';
            $updatesUntil = $featureSettings['license_updates_until'] ?? '';

            return match ($status) {
                'active' => $updatesUntil !== ''
                    ? 'License active - updates until '.substr((string) $updatesUntil, 0, 10)
                    : 'License active',
                'invalid' => 'License invalid or expired - check your key',
                'pending' => 'Enter your license key above and save to activate',
                default => 'No license configured - enter your key above and save to activate',
            };
        }

        return parent::getFormNotes($section);
    }
}
