<?php

namespace Modules\Stock\Enum;

use Exception;
use Modules\Stock\Trait\EnumTrait;

enum TypeEnteteEnum
{
    use EnumTrait;

    case DS;
    case BE;
    case BS;
    case BT;
    case BR;
    case I;
    case IN;
    case MV;
    case PR;

    /**
     * @throws Exception
     */
    public static function tryFrom(string $name): TypeEnteteEnum
    {
        return match ($name) {
            self::DS->name => self::DS,
            self::BE->name => self::BE,
            self::BS->name => self::BS,
            self::BT->name => self::BT,
            self::BR->name => self::BR,
            self::IN->name => self::IN,
            self::I->name => self::I,
            default => throw new Exception('Aucun cas n\'existe pour le nom ' . $name)
        };
    }

    public function getColName(): string
    {
        return match ($this) {
            TypeEnteteEnum::I => 'NO_INV',
            TypeEnteteEnum::IN => 'NO_INDISP',
            default => 'NO_' . $this->name
        };
    }

    public function getReservationColName(): string
    {
        return match ($this) {
            TypeEnteteEnum::IN => 'NO_INDIS',
            default => $this->getColName()
        };
    }

    /**
     * @throws Exception
     */
    public function getTable(): string
    {
        return match ($this) {
            TypeEnteteEnum::DS => 'SDS_ENTE',
            TypeEnteteEnum::BE => 'SBE_ENTE',
            TypeEnteteEnum::BS => 'SBS_ENTE',
            TypeEnteteEnum::I  => 'SINVENTA',
            TypeEnteteEnum::BT => 'SBT_ENTE',
            TypeEnteteEnum::IN => 'SINDISPO',
            default => throw new Exception('Ce type d\'entité n\'entre pas dans le cadre de la numérotation paramétrable')
        };
    }
}
