import { describe, expect, test } from 'bun:test';
import { checkCondition, extractMaxTriggers } from '../src/functions/condition.js';

function createProperty(values) {
    return {
        get(key) {
            return values[key];
        },
    };
}

describe('condition helpers', () => {
    test('empty conditions are treated as pass-through', () => {
        expect(checkCondition(createProperty({ AGE: 1 }), null)).toBe(true);
        expect(extractMaxTriggers()).toBe(1);
    });

    test('scalar != comparisons work correctly', () => {
        expect(checkCondition(createProperty({ STR: 4 }), 'STR!=3')).toBe(true);
        expect(checkCondition(createProperty({ STR: 3 }), 'STR!=3')).toBe(false);
    });

    test('array membership operators stay compatible with legacy syntax', () => {
        const property = createProperty({ TLT: [1001, 1002], EVT: [2001] });
        expect(checkCondition(property, 'TLT?[1002,1003]')).toBe(true);
        expect(checkCondition(property, 'EVT![1002,1003]')).toBe(true);
        expect(checkCondition(property, 'EVT![2001,2002]')).toBe(false);
    });

    test('age-based trigger extraction counts repeated trigger windows', () => {
        expect(extractMaxTriggers('AGE?[5,18,60]')).toBe(3);
        expect(extractMaxTriggers('STR>10')).toBe(1);
    });
});
