<?php

declare(strict_types=1);

namespace KupShop\CatalogBundle\Enum;

enum ProductOrder
{
    case Code;
    case Title;
    case PriceWithVat;
    case DateAdded;
    case PiecesSold;
    case Updated;
    case InStore;
    case ProducerName;
    case Discount;
    case SoldPrice;
    case StockInDate;
    case InStoreAmount;
    case StoreValue;

    // No idea
    case PriceCommonDiscount;

    public static function tryFromString(string $orderByString): ?self
    {
        return match (str_replace('-', '', $orderByString)) {
            'code' => self::Code,
            'title' => self::Title,
            'price', 'priceWithVat' => self::PriceWithVat,
            'date', 'dateAdded' => self::DateAdded,
            'sell', 'piecesSold' => self::PiecesSold,
            'updated' => self::Updated,
            'store', 'inStore' => self::InStore,
            'producer' => self::ProducerName,
            'discount' => self::Discount,
            'soldPrice' => self::SoldPrice,
            'stockIn' => self::StockInDate,
            'inStoreAmount', 'storeAmount' => self::InStoreAmount,
            'storeValue' => self::StoreValue,

            default => null,
        };
    }

    public static function tryFromInt(int $orderBy): ?self
    {
        return match (abs($orderBy)) {
            1 => self::Code,
            2 => self::Title,
            3 => self::PriceWithVat,
            4 => self::DateAdded,
            5 => self::PiecesSold,
            6 => self::Updated,
            7 => self::InStore,
            8 => self::ProducerName,
            10 => self::Discount,
            11 => self::SoldPrice,
            12 => self::StockInDate,
            13 => self::InStoreAmount,
            14 => self::PriceCommonDiscount,
            15 => self::StoreValue,

            default => null,
        };
    }

    public function stringValue(): string
    {
        return match ($this) {
            self::Code => 'code',
            self::Title => 'title',
            self::PriceWithVat => 'price',
            self::DateAdded => 'date',
            self::PiecesSold => 'sell',
            self::Updated => 'updated',
            self::InStore => 'store',
            self::ProducerName => 'producer',
            self::Discount => 'discount',
            self::SoldPrice => 'soldPrice',
            self::StockInDate => 'stockIn',
            self::InStoreAmount => 'inStoreAmount',
            self::PriceCommonDiscount => 'priceCommonDiscount',
            self::StoreValue => 'storeValue',
        };
    }
}
