<?php

declare(strict_types=1);

/*
 * 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\TransactionalEmail;

final class TransactionalEmailTrigger
{
    public const string PAYMENT_INITIATED = 'payment_initiated';
    public const string ORDER_CREATED = 'order_created';
    public const string ORDER_PAID = 'order_paid';
    public const string ORDER_SHIPPED = 'order_shipped';
    public const string CART_ABANDONED = 'cart_abandoned';
    public const string ACCOUNT_CREATED = 'account_created';
    public const string ACCOUNT_VERIFIED = 'account_verified';
    public const string CUSTOM = 'custom';

    /**
     * @return array<string, array<string, string>>
     */
    public static function choices(): array
    {
        return [
            'Commande' => [
                'Paiement initié' => self::PAYMENT_INITIATED,
                'Commande créée' => self::ORDER_CREATED,
                'Achat payé' => self::ORDER_PAID,
                'Commande expédiée' => self::ORDER_SHIPPED,
                'Panier abandonné' => self::CART_ABANDONED,
            ],
            'Client' => [
                'Compte créé' => self::ACCOUNT_CREATED,
                'Compte activé' => self::ACCOUNT_VERIFIED,
            ],
            'Autre' => [
                'Action personnalisée' => self::CUSTOM,
            ],
        ];
    }

    public static function label(string $trigger): string
    {
        foreach (self::choices() as $choices) {
            if (!\is_array($choices)) {
                continue;
            }

            $label = array_flip($choices)[$trigger] ?? null;
            if (null !== $label) {
                return $label;
            }
        }

        return $trigger;
    }
}
