<?php

require_once __DIR__ . '/../config/database.php';
if (file_exists(__DIR__ . '/SystemConfigService.php')) {
    require_once __DIR__ . '/SystemConfigService.php';
}

class TradingStyleService
{
    public static function ensureSchema(): void
    {
        try {
            db()->exec("\n                CREATE TABLE IF NOT EXISTS trading_style_settings (\n                    id INT AUTO_INCREMENT PRIMARY KEY,\n                    style_key VARCHAR(50) NOT NULL UNIQUE,\n                    style_name VARCHAR(100) NOT NULL,\n                    forex_sl_pips INT NOT NULL DEFAULT 25,\n                    gold_sl_pips INT NOT NULL DEFAULT 300,\n                    forex_tp1_rr DECIMAL(5,2) NOT NULL DEFAULT 1.00,\n                    forex_tp2_rr DECIMAL(5,2) NOT NULL DEFAULT 2.00,\n                    forex_tp3_rr DECIMAL(5,2) NOT NULL DEFAULT 3.00,\n                    gold_tp1_rr DECIMAL(5,2) NOT NULL DEFAULT 1.00,\n                    gold_tp2_rr DECIMAL(5,2) NOT NULL DEFAULT 2.00,\n                    gold_tp3_rr DECIMAL(5,2) NOT NULL DEFAULT 3.00,\n                    risk_buffer_percent DECIMAL(5,2) NOT NULL DEFAULT 10.00,\n                    is_active TINYINT(1) NOT NULL DEFAULT 1,\n                    sort_order INT NOT NULL DEFAULT 0,\n                    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n                    updated_at TIMESTAMP NULL DEFAULT NULL\n                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4\n            ");

            self::addColumnIfMissing('forex_tp1_rr', "ALTER TABLE trading_style_settings ADD COLUMN forex_tp1_rr DECIMAL(5,2) NOT NULL DEFAULT 1.00 AFTER gold_sl_pips");
            self::addColumnIfMissing('forex_tp2_rr', "ALTER TABLE trading_style_settings ADD COLUMN forex_tp2_rr DECIMAL(5,2) NOT NULL DEFAULT 2.00 AFTER forex_tp1_rr");
            self::addColumnIfMissing('forex_tp3_rr', "ALTER TABLE trading_style_settings ADD COLUMN forex_tp3_rr DECIMAL(5,2) NOT NULL DEFAULT 3.00 AFTER forex_tp2_rr");
            self::addColumnIfMissing('gold_tp1_rr', "ALTER TABLE trading_style_settings ADD COLUMN gold_tp1_rr DECIMAL(5,2) NOT NULL DEFAULT 1.00 AFTER forex_tp3_rr");
            self::addColumnIfMissing('gold_tp2_rr', "ALTER TABLE trading_style_settings ADD COLUMN gold_tp2_rr DECIMAL(5,2) NOT NULL DEFAULT 2.00 AFTER gold_tp1_rr");
            self::addColumnIfMissing('gold_tp3_rr', "ALTER TABLE trading_style_settings ADD COLUMN gold_tp3_rr DECIMAL(5,2) NOT NULL DEFAULT 3.00 AFTER gold_tp2_rr");
            self::addColumnIfMissing('silver_sl_pips', "ALTER TABLE trading_style_settings ADD COLUMN silver_sl_pips INT NOT NULL DEFAULT 100 AFTER gold_tp3_rr");
            self::addColumnIfMissing('silver_tp1_rr', "ALTER TABLE trading_style_settings ADD COLUMN silver_tp1_rr DECIMAL(5,2) NOT NULL DEFAULT 1.00 AFTER silver_sl_pips");
            self::addColumnIfMissing('silver_tp2_rr', "ALTER TABLE trading_style_settings ADD COLUMN silver_tp2_rr DECIMAL(5,2) NOT NULL DEFAULT 2.00 AFTER silver_tp1_rr");
            self::addColumnIfMissing('silver_tp3_rr', "ALTER TABLE trading_style_settings ADD COLUMN silver_tp3_rr DECIMAL(5,2) NOT NULL DEFAULT 3.00 AFTER silver_tp2_rr");

            self::addColumnIfMissing('crypto_sl_pips', "ALTER TABLE trading_style_settings ADD COLUMN crypto_sl_pips INT NOT NULL DEFAULT 500 AFTER silver_tp3_rr");
            self::addColumnIfMissing('crypto_tp1_rr', "ALTER TABLE trading_style_settings ADD COLUMN crypto_tp1_rr DECIMAL(5,2) NOT NULL DEFAULT 1.00 AFTER crypto_sl_pips");
            self::addColumnIfMissing('crypto_tp2_rr', "ALTER TABLE trading_style_settings ADD COLUMN crypto_tp2_rr DECIMAL(5,2) NOT NULL DEFAULT 2.00 AFTER crypto_tp1_rr");
            self::addColumnIfMissing('crypto_tp3_rr', "ALTER TABLE trading_style_settings ADD COLUMN crypto_tp3_rr DECIMAL(5,2) NOT NULL DEFAULT 3.00 AFTER crypto_tp2_rr");

            self::addColumnIfMissing('indices_sl_pips', "ALTER TABLE trading_style_settings ADD COLUMN indices_sl_pips INT NOT NULL DEFAULT 100 AFTER crypto_tp3_rr");
            self::addColumnIfMissing('indices_tp1_rr', "ALTER TABLE trading_style_settings ADD COLUMN indices_tp1_rr DECIMAL(5,2) NOT NULL DEFAULT 1.00 AFTER indices_sl_pips");
            self::addColumnIfMissing('indices_tp2_rr', "ALTER TABLE trading_style_settings ADD COLUMN indices_tp2_rr DECIMAL(5,2) NOT NULL DEFAULT 2.00 AFTER indices_tp1_rr");
            self::addColumnIfMissing('indices_tp3_rr', "ALTER TABLE trading_style_settings ADD COLUMN indices_tp3_rr DECIMAL(5,2) NOT NULL DEFAULT 3.00 AFTER indices_tp2_rr");

            self::addColumnIfMissing('commodities_sl_pips', "ALTER TABLE trading_style_settings ADD COLUMN commodities_sl_pips INT NOT NULL DEFAULT 100 AFTER indices_tp3_rr");
            self::addColumnIfMissing('commodities_tp1_rr', "ALTER TABLE trading_style_settings ADD COLUMN commodities_tp1_rr DECIMAL(5,2) NOT NULL DEFAULT 1.00 AFTER commodities_sl_pips");
            self::addColumnIfMissing('commodities_tp2_rr', "ALTER TABLE trading_style_settings ADD COLUMN commodities_tp2_rr DECIMAL(5,2) NOT NULL DEFAULT 2.00 AFTER commodities_tp1_rr");
            self::addColumnIfMissing('commodities_tp3_rr', "ALTER TABLE trading_style_settings ADD COLUMN commodities_tp3_rr DECIMAL(5,2) NOT NULL DEFAULT 3.00 AFTER commodities_tp2_rr");

            self::addColumnIfMissing('stocks_sl_pips', "ALTER TABLE trading_style_settings ADD COLUMN stocks_sl_pips INT NOT NULL DEFAULT 100 AFTER commodities_tp3_rr");
            self::addColumnIfMissing('stocks_tp1_rr', "ALTER TABLE trading_style_settings ADD COLUMN stocks_tp1_rr DECIMAL(5,2) NOT NULL DEFAULT 1.00 AFTER stocks_sl_pips");
            self::addColumnIfMissing('stocks_tp2_rr', "ALTER TABLE trading_style_settings ADD COLUMN stocks_tp2_rr DECIMAL(5,2) NOT NULL DEFAULT 2.00 AFTER stocks_tp1_rr");
            self::addColumnIfMissing('stocks_tp3_rr', "ALTER TABLE trading_style_settings ADD COLUMN stocks_tp3_rr DECIMAL(5,2) NOT NULL DEFAULT 3.00 AFTER stocks_tp2_rr");

            self::addColumnIfMissing('risk_buffer_percent', "ALTER TABLE trading_style_settings ADD COLUMN risk_buffer_percent DECIMAL(5,2) NOT NULL DEFAULT 10.00 AFTER stocks_tp3_rr");
            self::addColumnIfMissing('sort_order', "ALTER TABLE trading_style_settings ADD COLUMN sort_order INT NOT NULL DEFAULT 0 AFTER is_active");
            self::addColumnIfMissing('updated_at', "ALTER TABLE trading_style_settings ADD COLUMN updated_at TIMESTAMP NULL DEFAULT NULL AFTER created_at");

            $count = (int) db()->query("SELECT COUNT(*) FROM trading_style_settings")->fetchColumn();

            if ($count === 0) {
                $stmt = db()->prepare("\n                    INSERT INTO trading_style_settings\n                    (style_key, style_name, forex_sl_pips, gold_sl_pips, silver_sl_pips, forex_tp1_rr, forex_tp2_rr, forex_tp3_rr, gold_tp1_rr, gold_tp2_rr, gold_tp3_rr, silver_tp1_rr, silver_tp2_rr, silver_tp3_rr, risk_buffer_percent, is_active, sort_order)\n                    VALUES\n                    (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n                ");

                $defaults = [
                    ['scalping', 'Scalping', 15, 150, 50, 1.00, 1.50, 2.00, 1.00, 1.50, 2.00, 1.00, 1.50, 2.00, 12.00, 1, 1],
                    ['intraday', 'Intraday', 30, 300, 100, 1.00, 2.00, 3.00, 1.00, 2.00, 3.00, 1.00, 2.00, 3.00, 10.00, 1, 2],
                    ['swing', 'Swing Trading', 70, 700, 250, 1.50, 3.00, 5.00, 1.50, 3.00, 5.00, 1.50, 3.00, 5.00, 10.00, 1, 3],
                    ['auto', 'Auto Volatility Mode', 35, 350, 120, 1.00, 2.00, 3.50, 1.00, 2.00, 3.50, 1.00, 2.00, 3.50, 12.00, 1, 4],
                ];

                foreach ($defaults as $row) {
                    $stmt->execute($row);
                }
            }
        } catch (Throwable $e) {
            // Fail silently so the dashboard does not break if DB permissions are limited.
        }
    }

    private static function addColumnIfMissing(string $column, string $sql): void
    {
        try {
            $stmt = db()->prepare("\n                SELECT COUNT(*)\n                FROM INFORMATION_SCHEMA.COLUMNS\n                WHERE TABLE_SCHEMA = DATABASE()\n                AND TABLE_NAME = 'trading_style_settings'\n                AND COLUMN_NAME = ?\n            ");
            $stmt->execute([$column]);

            if ((int) $stmt->fetchColumn() === 0) {
                db()->exec($sql);
            }
        } catch (Throwable $e) {
            // Ignore schema migration error.
        }
    }

    public static function getActiveStyles(): array
    {
        self::ensureSchema();

        try {
            $stmt = db()->query("\n                SELECT *\n                FROM trading_style_settings\n                WHERE is_active = 1\n                ORDER BY sort_order ASC, id ASC\n            ");

            return $stmt->fetchAll(PDO::FETCH_ASSOC);
        } catch (Throwable $e) {
            return [];
        }
    }

    public static function getStyle(string $styleKey = ''): array
    {
        self::ensureSchema();

        $styleKey = trim($styleKey);

        try {
            if ($styleKey !== '') {
                $stmt = db()->prepare("\n                    SELECT *\n                    FROM trading_style_settings\n                    WHERE style_key = ?\n                    AND is_active = 1\n                    LIMIT 1\n                ");
                $stmt->execute([$styleKey]);
                $style = $stmt->fetch(PDO::FETCH_ASSOC);

                if ($style) {
                    return self::normalize($style);
                }
            }

            $stmt = db()->query("\n                SELECT *\n                FROM trading_style_settings\n                WHERE is_active = 1\n                ORDER BY sort_order ASC, id ASC\n                LIMIT 1\n            ");
            $style = $stmt->fetch(PDO::FETCH_ASSOC);

            if ($style) {
                return self::normalize($style);
            }
        } catch (Throwable $e) {
            // Continue to safe fallback.
        }

        return self::normalize([
            'style_key' => 'intraday',
            'style_name' => 'Intraday',
            'forex_sl_pips' => 30,
            'gold_sl_pips' => 300,
            'silver_sl_pips' => 100,
            'forex_tp1_rr' => 1.00,
            'forex_tp2_rr' => 2.00,
            'forex_tp3_rr' => 3.00,
            'gold_tp1_rr' => 1.00,
            'gold_tp2_rr' => 2.00,
            'gold_tp3_rr' => 3.00,
            'silver_tp1_rr' => 1.00,
            'silver_tp2_rr' => 2.00,
            'silver_tp3_rr' => 3.00,
            'crypto_sl_pips' => 500,
            'crypto_tp1_rr' => 1.00,
            'crypto_tp2_rr' => 2.00,
            'crypto_tp3_rr' => 3.00,
            'indices_sl_pips' => 100,
            'indices_tp1_rr' => 1.00,
            'indices_tp2_rr' => 2.00,
            'indices_tp3_rr' => 3.00,
            'commodities_sl_pips' => 100,
            'commodities_tp1_rr' => 1.00,
            'commodities_tp2_rr' => 2.00,
            'commodities_tp3_rr' => 3.00,
            'stocks_sl_pips' => 100,
            'stocks_tp1_rr' => 1.00,
            'stocks_tp2_rr' => 2.00,
            'stocks_tp3_rr' => 3.00,
            'risk_buffer_percent' => 10.00,
        ]);
    }

    public static function normalize(array $style): array
    {
        return [
            'id' => isset($style['id']) ? (int) $style['id'] : 0,
            'style_key' => (string)($style['style_key'] ?? 'intraday'),
            'style_name' => (string)($style['style_name'] ?? 'Intraday'),

            'forex_sl_pips' => max(1, (int)($style['forex_sl_pips'] ?? 30)),
            'gold_sl_pips' => max(1, (int)($style['gold_sl_pips'] ?? 300)),
            'silver_sl_pips' => max(1, (int)($style['silver_sl_pips'] ?? 100)),
            'crypto_sl_pips' => max(1, (int)($style['crypto_sl_pips'] ?? 500)),
            'indices_sl_pips' => max(1, (int)($style['indices_sl_pips'] ?? 100)),
            'commodities_sl_pips' => max(1, (int)($style['commodities_sl_pips'] ?? 100)),
            'stocks_sl_pips' => max(1, (int)($style['stocks_sl_pips'] ?? 100)),

            'forex_tp1_rr' => max(0.1, (float)($style['forex_tp1_rr'] ?? 1.00)),
            'forex_tp2_rr' => max(0.1, (float)($style['forex_tp2_rr'] ?? 2.00)),
            'forex_tp3_rr' => max(0.1, (float)($style['forex_tp3_rr'] ?? 3.00)),

            'gold_tp1_rr' => max(0.1, (float)($style['gold_tp1_rr'] ?? 1.00)),
            'gold_tp2_rr' => max(0.1, (float)($style['gold_tp2_rr'] ?? 2.00)),
            'gold_tp3_rr' => max(0.1, (float)($style['gold_tp3_rr'] ?? 3.00)),

            'silver_tp1_rr' => max(0.1, (float)($style['silver_tp1_rr'] ?? ($style['gold_tp1_rr'] ?? 1.00))),
            'silver_tp2_rr' => max(0.1, (float)($style['silver_tp2_rr'] ?? ($style['gold_tp2_rr'] ?? 2.00))),
            'silver_tp3_rr' => max(0.1, (float)($style['silver_tp3_rr'] ?? ($style['gold_tp3_rr'] ?? 3.00))),

            'crypto_tp1_rr' => max(0.1, (float)($style['crypto_tp1_rr'] ?? 1.00)),
            'crypto_tp2_rr' => max(0.1, (float)($style['crypto_tp2_rr'] ?? 2.00)),
            'crypto_tp3_rr' => max(0.1, (float)($style['crypto_tp3_rr'] ?? 3.00)),

            'indices_tp1_rr' => max(0.1, (float)($style['indices_tp1_rr'] ?? 1.00)),
            'indices_tp2_rr' => max(0.1, (float)($style['indices_tp2_rr'] ?? 2.00)),
            'indices_tp3_rr' => max(0.1, (float)($style['indices_tp3_rr'] ?? 3.00)),

            'commodities_tp1_rr' => max(0.1, (float)($style['commodities_tp1_rr'] ?? 1.00)),
            'commodities_tp2_rr' => max(0.1, (float)($style['commodities_tp2_rr'] ?? 2.00)),
            'commodities_tp3_rr' => max(0.1, (float)($style['commodities_tp3_rr'] ?? 3.00)),

            'stocks_tp1_rr' => max(0.1, (float)($style['stocks_tp1_rr'] ?? 1.00)),
            'stocks_tp2_rr' => max(0.1, (float)($style['stocks_tp2_rr'] ?? 2.00)),
            'stocks_tp3_rr' => max(0.1, (float)($style['stocks_tp3_rr'] ?? 3.00)),

            'risk_buffer_percent' => max(0, (float)($style['risk_buffer_percent'] ?? 10.00)),
        ];
    }


    public static function pipSize(string $symbol): float
    {
        $symbol = strtoupper(str_replace(['/', '-', '_', ' '], '', trim($symbol)));

        try {
            if (class_exists('SystemConfigService') && method_exists('SystemConfigService', 'getPipSize')) {
                $pipSize = (float)SystemConfigService::getPipSize($symbol);
                if ($pipSize > 0) {
                    return $pipSize;
                }
            }
        } catch (Throwable $e) {
        }

        if ($symbol === 'XAUUSD') {
            return 0.1;
        }

        if ($symbol === 'XAGUSD') {
            return 0.01;
        }

        if (strpos($symbol, 'JPY') !== false) {
            return 0.01;
        }

        if (preg_match('/^[A-Z]{6}$/', $symbol)) {
            return 0.0001;
        }

        return 1.0;
    }


    public static function cryptoStopPipsForSymbol(string $symbol, string $styleKey = 'intraday'): int
    {
        $symbol = strtoupper(str_replace(['/', '-', '_', ' '], '', trim($symbol)));
        $styleKey = strtolower(trim($styleKey));

        if (strpos($symbol, 'BTC') === 0) {
            if ($styleKey === 'scalping') {
                return 200;
            }

            if ($styleKey === 'swing') {
                return 1500;
            }

            if ($styleKey === 'auto') {
                return 600;
            }

            return 500;
        }

        if (strpos($symbol, 'ETH') === 0) {
            if ($styleKey === 'scalping') {
                return 10;
            }

            if ($styleKey === 'swing') {
                return 75;
            }

            if ($styleKey === 'auto') {
                return 30;
            }

            return 25;
        }

        if ($styleKey === 'scalping') {
            return 25;
        }

        if ($styleKey === 'swing') {
            return 150;
        }

        if ($styleKey === 'auto') {
            return 60;
        }

        return 50;
    }

    public static function assetExecutionKey(string $symbol): string
    {
        $symbol = strtoupper(str_replace(['/', '-', '_', ' '], '', trim($symbol)));

        try {
            if (class_exists('SystemConfigService') && method_exists('SystemConfigService', 'getSymbolConfig')) {
                $config = SystemConfigService::getSymbolConfig($symbol);
                $assetType = strtoupper((string)($config['asset_type'] ?? ''));

                if (in_array($assetType, ['CRYPTO', 'CRYPTOCURRENCY'], true)) {
                    return 'crypto';
                }

                if (in_array($assetType, ['INDEX', 'INDICES', 'INDEXES'], true)) {
                    return 'indices';
                }

                if (in_array($assetType, ['COMMODITY', 'COMMODITIES'], true)) {
                    return 'commodities';
                }

                if (in_array($assetType, ['STOCK', 'STOCKS'], true)) {
                    return 'stocks';
                }
            }
        } catch (Throwable $e) {
        }

        if (preg_match('/^(BTC|ETH|BNB|SOL|XRP|ADA|DOGE|LTC|BCH|AVAX|DOT|MATIC|TRX|LINK|ATOM|NEAR|APT|OP|ARB)/', $symbol)) {
            return 'crypto';
        }

        if ($symbol === 'XAUUSD') {
            return 'gold';
        }

        if ($symbol === 'XAGUSD') {
            return 'silver';
        }

        if (strpos($symbol, 'NAS') !== false || strpos($symbol, 'US30') !== false || strpos($symbol, 'SPX') !== false || strpos($symbol, 'GER') !== false || strpos($symbol, 'US100') !== false) {
            return 'indices';
        }

        if (strpos($symbol, 'JPY') !== false || preg_match('/^[A-Z]{6}$/', $symbol)) {
            return 'forex';
        }

        return 'forex';
    }


    public static function getStopDistance(string $symbol, array $style): float
    {
        $symbol = strtoupper(str_replace(['/', '-', '_', ' '], '', trim($symbol)));
        $style = self::normalize($style);
        $key = self::assetExecutionKey($symbol);

        if ($key === 'crypto') {
            return self::cryptoStopPipsForSymbol($symbol, (string)($style['style_key'] ?? 'intraday')) * self::pipSize($symbol);
        }

        $column = $key . '_sl_pips';
        $pips = (float)($style[$column] ?? 0);

        if ($pips <= 0) {
            $pips = (float)($style['forex_sl_pips'] ?? 30);
        }

        return $pips * self::pipSize($symbol);
    }


    public static function getTpMultipliers(string $symbol, array $style): array
    {
        $style = self::normalize($style);
        $key = self::assetExecutionKey($symbol);

        $prefix = in_array($key, ['gold', 'silver', 'crypto', 'indices', 'commodities', 'stocks', 'forex'], true)
            ? $key
            : 'forex';

        return [
            'tp1' => $style[$prefix . '_tp1_rr'] ?? $style['forex_tp1_rr'],
            'tp2' => $style[$prefix . '_tp2_rr'] ?? $style['forex_tp2_rr'],
            'tp3' => $style[$prefix . '_tp3_rr'] ?? $style['forex_tp3_rr'],
        ];
    }


    public static function stopDistance(string $symbol, array $style): float
    {
        return self::getStopDistance($symbol, $style);
    }

    public static function stopPips(string $symbol, array $style): int
    {
        $symbol = strtoupper(str_replace(['/', '-', '_', ' '], '', trim($symbol)));
        $style = self::normalize($style);
        $key = self::assetExecutionKey($symbol);

        if ($key === 'crypto') {
            return self::cryptoStopPipsForSymbol($symbol, (string)($style['style_key'] ?? 'intraday'));
        }

        $column = $key . '_sl_pips';

        return (int)($style[$column] ?? $style['forex_sl_pips']);
    }


    public static function tpMultipliers(string $symbol, array $style): array
    {
        return self::getTpMultipliers($symbol, $style);
    }

    public static function rrLabel(string $symbol, array $style): string
    {
        $tp = self::getTpMultipliers($symbol, $style);
        return '1:' . number_format((float)$tp['tp1'], 2) . ' / 1:' . number_format((float)$tp['tp2'], 2) . ' / 1:' . number_format((float)$tp['tp3'], 2);
    }

    public static function distanceLabel(string $symbol, float $distance): string
    {
        $symbol = strtoupper(str_replace(['/', '-', '_', ' '], '', trim($symbol)));
        $pipSize = self::pipSize($symbol);
        $pips = $pipSize > 0 ? round($distance / $pipSize) : 0;

        if ($symbol === 'XAUUSD') {
            return number_format($distance, 2) . ' Gold points (' . $pips . ' pips)';
        }

        if ($symbol === 'XAGUSD') {
            return number_format($distance, 3) . ' Silver points (' . $pips . ' pips)';
        }

        $decimals = 2;
        try {
            if (class_exists('SystemConfigService') && method_exists('SystemConfigService', 'priceDecimals')) {
                $decimals = (int)SystemConfigService::priceDecimals($symbol);
            } elseif (class_exists('RiskService') && method_exists('RiskService', 'priceDecimals')) {
                $decimals = (int)RiskService::priceDecimals($symbol);
            }
        } catch (Throwable $e) {
        }

        return number_format($distance, max(0, $decimals), '.', '') . ' (' . number_format($pips, 0) . ' pips)';
    }


    public static function maxEntryDistance(string $symbol, array $style): float
    {
        $symbol = strtoupper(str_replace(['/', '-', '_', ' '], '', trim($symbol)));
        $style = self::normalize($style);
        $styleKey = strtolower($style['style_key'] ?? 'intraday');
        $assetKey = self::assetExecutionKey($symbol);

        if ($symbol === 'XAUUSD') {
            if ($styleKey === 'scalping') return 2.5;
            if ($styleKey === 'intraday') return 6.0;
            if ($styleKey === 'swing') return 18.0;
            return 8.0;
        }

        if ($symbol === 'XAGUSD') {
            if ($styleKey === 'scalping') return 0.25;
            if ($styleKey === 'intraday') return 0.60;
            if ($styleKey === 'swing') return 1.50;
            return 0.80;
        }

        if ($assetKey === 'crypto') {
            $pipSize = self::pipSize($symbol);
            if ($styleKey === 'scalping') return 150 * $pipSize;
            if ($styleKey === 'intraday') return 500 * $pipSize;
            if ($styleKey === 'swing') return 1500 * $pipSize;
            return 600 * $pipSize;
        }

        if (strpos($symbol, 'JPY') !== false) {
            if ($styleKey === 'scalping') return 0.20;
            if ($styleKey === 'intraday') return 0.50;
            if ($styleKey === 'swing') return 1.20;
            return 0.60;
        }

        if ($styleKey === 'scalping') return 0.0020;
        if ($styleKey === 'intraday') return 0.0050;
        if ($styleKey === 'swing') return 0.0120;
        return 0.0060;
    }
}
