<?php
namespace App\Enums\Market;


use App\Enums\Market\TransactionFlow;


enum ProductTransactionType: int
{
    // General
    case UNKNOWN = 0;

    // Sales & Purchases
    case ONLINE_SALE = 1;
    case STORE_SALE = 2;
    case WHOLESALE_SALE = 3;
    case PURCHASE = 4;

    // Transfers
    case STORE_TO_STORE_TRANSFER = 5;
    case OWNER_TO_OWNER_TRANSFER = 6;

    // Stock Management
    case INVENTORY_ADJUSTMENT = 7;
    case STOCK_RETURN = 8;
    case RECEIVING = 9;

    // System / Admin
    case INTERNAL_UPDATE = 10;
    case ULTIMATE_UPDATE = 11;
    case AUDIT_UPDATE = 12;
    case SYSTEM_CORRECTION = 13;
    case MANUAL_OVERRIDE = 14;
    case DATA_IMPORT = 15;
    case TOP_UP = 16;
    case TRANSFER = 17;

    public function label(): string
    {
        return match($this) {
            self::UNKNOWN => 'Unknown',
            self::ONLINE_SALE => 'Online Sale',
            self::STORE_SALE => 'Store Sale',
            self::WHOLESALE_SALE => 'Wholesale Sale',
            self::PURCHASE => 'Purchase',
            self::STORE_TO_STORE_TRANSFER => 'Store-to-Store Transfer',
            self::OWNER_TO_OWNER_TRANSFER => 'Owner-to-Owner Transfer',
            self::INVENTORY_ADJUSTMENT => 'Inventory Adjustment',
            self::STOCK_RETURN => 'Stock Return',
            self::RECEIVING => 'Receiving',
            self::INTERNAL_UPDATE => 'Internal Update',
            self::ULTIMATE_UPDATE => 'Ultimate Update',
            self::AUDIT_UPDATE => 'Audit Update',
            self::SYSTEM_CORRECTION => 'System Correction',
            self::MANUAL_OVERRIDE => 'Manual Override',
            self::DATA_IMPORT => 'Data Import',
            self::TOP_UP => 'Top Up',
            self::TRANSFER => 'Transfer',
        };
    }

    public function flow(): TransactionFlow
    {
        return match($this) {
            self::ONLINE_SALE, 
            self::STORE_SALE, 
            self::WHOLESALE_SALE,
            self::TOP_UP => TransactionFlow::INCOME,
            
            self::PURCHASE => TransactionFlow::EXPENSE,
            
            self::TRANSFER => TransactionFlow::NEUTRAL,
            
            self::STOCK_RETURN => TransactionFlow::NEUTRAL, // Or EXPENSE if it's a return to supplier, keeping neutral for now as default
            
            default => TransactionFlow::NEUTRAL,
        };
    }

    public static function options(): array
    {
        return collect(self::cases())
            ->mapWithKeys(fn ($case) => [$case->value => $case->label()])
            ->toArray();
    }
}