import assert from 'node:assert/strict';
import { SessionRule } from './src/strategies/rules/SessionRule.js';
import { SignalDirection, type MarketContext } from './src/strategies/rules/types.js';

const buildContext = (session: string): MarketContext => ({
    symbol: 'SOL/USDT',
    candles4h: [],
    candles1h: [],
    candles15m: [],
    currentPrice: 100,
    change24h: 0,
    changeToday: 0,
    session,
    isMajorSession: false,
    volatility: 'High',
    latestSignal: SignalDirection.NONE
});

async function run() {
    const rule = new SessionRule();
    const tokSydContext = buildContext('TOK | SYD');
    const ldnContext = buildContext('LDN');

    const direct24h = await rule.check(tokSydContext, { sessions: '24/7' });
    assert.equal(direct24h.passed, true, 'string 24/7 must always pass');

    const array24h = await rule.check(tokSydContext, { sessions: ['24/7'] });
    assert.equal(array24h.passed, true, 'array ["24/7"] must always pass');

    const spaced24h = await rule.check(tokSydContext, { sessions: ['24 / 7'] });
    assert.equal(spaced24h.passed, true, 'array ["24 / 7"] must always pass');

    const legacy24x7 = await rule.check(tokSydContext, { sessions: ['24x7'] });
    assert.equal(legacy24x7.passed, true, 'legacy 24x7 token must always pass');

    const unicodeFractionSlash = await rule.check(tokSydContext, { sessions: ['24⁄7'] });
    assert.equal(unicodeFractionSlash.passed, true, 'unicode fraction slash 24⁄7 must always pass');

    const unicodeDivisionSlash = await rule.check(tokSydContext, { sessions: ['24∕7'] });
    assert.equal(unicodeDivisionSlash.passed, true, 'unicode division slash 24∕7 must always pass');

    const unicodeFullwidthSlash = await rule.check(tokSydContext, { sessions: ['24／7'] });
    assert.equal(unicodeFullwidthSlash.passed, true, 'unicode fullwidth slash 24／7 must always pass');

    const unicodeMultiply = await rule.check(tokSydContext, { sessions: ['24×7'] });
    assert.equal(unicodeMultiply.passed, true, 'unicode multiply 24×7 must always pass');

    const restricted = await rule.check(tokSydContext, { sessions: 'LDN,NY' });
    assert.equal(restricted.passed, false, 'LDN/NY schedule must block TOK/SYD session');

    const asiaAliases = await rule.check(tokSydContext, { sessions: 'Tokyo,Sydney' });
    assert.equal(asiaAliases.passed, true, 'Tokyo/Sydney aliases must map to TOK/SYD');

    const defaultSchedule = await rule.check(tokSydContext, {});
    assert.equal(defaultSchedule.passed, false, 'default schedule must remain LDN/NY only');

    const defaultDuringLdn = await rule.check(ldnContext, {});
    assert.equal(defaultDuringLdn.passed, true, 'default schedule must pass during LDN');

    console.log('[session-rule-normalization] OK: session token normalization and 24/7 handling checks passed');
}

await run();
