<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Altcha;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\ContactFormType;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\PaymentType;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\ProductReviewReportType;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\Security\RegisterConfirmType;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\Security\ResetPasswordType;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Site\Withdrawal\WithdrawalRequestType;

/**
 * Contrat métier VitiCore vers les scopes du service ALTCHA.
 *
 * L'absence d'un type dans cette liste est volontaire : aucune protection
 * ALTCHA ne doit être injectée implicitement dans les autres formulaires.
 */
final class VitiCoreAltchaProtection
{
    public const string CONTACT = 'site.contact';
    public const string REGISTRATION_CONFIRM = 'security.registration_confirm';
    public const string PASSWORD_RESET = 'security.password_reset';
    public const string PAYMENT = 'payment.online';
    public const string PRODUCT_REVIEW_REPORT = 'marketing.product_review_report';
    public const string WITHDRAWAL = 'shop.withdrawal';

    /** @var array<class-string, string> */
    private const array SCOPES = [
        ContactFormType::class => self::CONTACT,
        RegisterConfirmType::class => self::REGISTRATION_CONFIRM,
        ResetPasswordType::class => self::PASSWORD_RESET,
        PaymentType::class => self::PAYMENT,
        ProductReviewReportType::class => self::PRODUCT_REVIEW_REPORT,
        WithdrawalRequestType::class => self::WITHDRAWAL,
    ];

    /** @var array<class-string, list<string>> */
    private const array PARTIAL_LIVE_ACTIONS = [
        RegisterConfirmType::class => ['validatePasswords'],
        ResetPasswordType::class => ['validatePasswords'],
    ];

    /** @var array<class-string, list<string>> */
    private const array FINAL_LIVE_ACTIONS = [
        ContactFormType::class => ['submitContact'],
        RegisterConfirmType::class => ['submitRegisterConfirm'],
        ResetPasswordType::class => ['submitResetPassword'],
        PaymentType::class => ['submitPayment'],
    ];

    /** @param class-string $formType */
    public static function scopeFor(string $formType): ?string
    {
        return self::SCOPES[$formType] ?? null;
    }

    /**
     * @param class-string $formType
     *
     * @return list<string>
     */
    public static function partialLiveActionsFor(string $formType): array
    {
        return self::PARTIAL_LIVE_ACTIONS[$formType] ?? [];
    }

    /**
     * @param class-string $formType
     *
     * @return list<string>
     */
    public static function finalLiveActionsFor(string $formType): array
    {
        return self::FINAL_LIVE_ACTIONS[$formType] ?? [];
    }

    /** @return list<string> */
    public static function scopes(): array
    {
        return array_values(array_unique(self::SCOPES));
    }

    private function __construct()
    {
    }
}
