<?php

namespace Entity\Model\Enum;

use Helpers\Outil\Sql;
use Helpers\Trad\ITrad;

enum EFacDematFlowStatus : int implements ILabelized
{
    // case Déposée = 200;
    // case Emise par la plateforme = 201;
    // case Reçue par la plateforme = 202;
    case MiseADispo = 203;
    case PrisEnCharge = 204;
    case Appro = 205;
    case ApproPartiel = 206;
    case Litige = 207;
    case Suspendue = 208;
    case Complet = 209;
    case Refuse = 210;
    case PaieTrans = 211;
    case Encaisse = 212;
    // case Rejete = 213;
    case Annuler = 220;

    public function getLabel(?ITrad $trad = null) :string
    {
        if ($trad) {
            return match ($this) {
                static::MiseADispo => $trad->t('Mise à disposition'),
                static::PrisEnCharge => $trad->t('Prise en charge'),
                static::Appro => $trad->t('Approuvée'),
                static::ApproPartiel => $trad->t('Approuvée partiellement'),
                static::Litige => $trad->t('En litige'),
                static::Suspendue => $trad->t('Suspendue'),
                static::Complet => $trad->t('Complétée'),
                static::Refuse => $trad->t('Refusée'),
                static::PaieTrans => $trad->t('Paiement transmis'),
                static::Encaisse => $trad->t('Encaissée'),
                static::Annuler => $trad->t('Annulée'),
                //default => '#' . $this->value,
            };
        }
        return match ($this) {
            static::MiseADispo => 'Mise à disposition',
            static::PrisEnCharge => 'Prise en charge',
            static::Appro => 'Approuvée',
            static::ApproPartiel => 'Approuvée partiellement',
            static::Litige => 'En litige',
            static::Suspendue => 'Suspendue',
            static::Complet => 'Complétée',
            static::Refuse => 'Refusée',
            static::PaieTrans => 'Paiement transmis',
            static::Encaisse => 'Encaissée',
            static::Annuler => 'Annulée',
            //default => '#' . $this->value,
        };
    }

    /**
     * @param array<mixed> $facEnt
     */
    public static function calcFacStatus(array $facEnt) :self
    {
        if (Sql::toBool($facEnt['LITIGE'])) {
            return self::Litige;
        }
        if (Sql::toBool($facEnt['REFUSEE_FE'])) {
            return self::Refuse;
        }
        if (Sql::toBool($facEnt['ANNULE'])) {
            return self::Annuler;
        }
        if (Sql::toBool($facEnt['BON_A_PAY'])) {
            return self::Appro;
        }
        if (Sql::toBool($facEnt['ENT_VALID'])) {
            return self::PrisEnCharge;
        }
        return self::MiseADispo;
    }
}
