"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = __importDefault(require("node:test"));
const strict_1 = __importDefault(require("node:assert/strict"));
const index_1 = require("../src/index");
function runtime(overrides = {}) {
    return {
        client: 'web',
        clientVersion: '1.0.0',
        clientBuild: 3,
        platform: 'macos',
        platformVersion: '14.0',
        ...overrides,
    };
}
(0, node_test_1.default)('accepts newer client version even if build is below minimum for previous release', () => {
    const info = runtime({ clientVersion: '1.0.1', clientBuild: 1 });
    const result = (0, index_1.validateClientEnvironment)(info);
    strict_1.default.equal(result.ok, true);
});
(0, node_test_1.default)('enforces minimum build when version matches requirement', () => {
    const meta = (0, index_1.loadClientMeta)();
    const requiredVersion = meta.clients['all']?.minimumVersion ?? meta.version;
    const requiredBuild = meta.clients['all']?.minimumBuild;
    if (typeof requiredBuild !== 'number') {
        strict_1.default.equal(true, true);
        return;
    }
    const info = runtime({ clientVersion: requiredVersion, clientBuild: Math.max(requiredBuild - 1, 0) });
    const result = (0, index_1.validateClientEnvironment)(info);
    strict_1.default.equal(result.ok, false);
    if (!result.ok) {
        strict_1.default.equal(result.code, 'unsupported_client_build');
        strict_1.default.equal(result.requiredBuild, requiredBuild);
    }
});
(0, node_test_1.default)('enforces minimum version before build check', () => {
    const info = runtime({ clientVersion: '0.0.9', clientBuild: 99 });
    const result = (0, index_1.validateClientEnvironment)(info);
    strict_1.default.equal(result.ok, false);
    if (!result.ok) {
        strict_1.default.equal(result.code, 'unsupported_client_version');
    }
});
(0, node_test_1.default)('accepts supported clients without platform-specific floors', () => {
    const info = runtime({ platform: 'ios', platformVersion: '15.5', client: 'apple-playdrop-ios' });
    const result = (0, index_1.validateClientEnvironment)(info);
    strict_1.default.equal(result.ok, true);
});
(0, node_test_1.default)('accepts product-specific Apple client ids that meet the minimum version', () => {
    const meta = (0, index_1.loadClientMeta)();
    for (const clientName of ['apple-playdrop-ios', 'apple-playdrop-mac', 'apple-games', 'apple-music']) {
        const requiredVersion = meta.clients['all']?.minimumVersion ?? meta.version;
        const requiredBuild = meta.clients['all']?.minimumBuild ?? meta.build;
        const info = runtime({
            client: clientName,
            clientVersion: requiredVersion,
            clientBuild: requiredBuild,
            platform: 'ios',
            platformVersion: '18.0',
        });
        const result = (0, index_1.validateClientEnvironment)(info);
        strict_1.default.equal(result.ok, true, clientName);
    }
});
(0, node_test_1.default)('accepts android-games as a first-class client identity', () => {
    const meta = (0, index_1.loadClientMeta)();
    const requiredVersion = meta.clients['all']?.minimumVersion ?? meta.version;
    const requiredBuild = meta.clients['all']?.minimumBuild ?? meta.build;
    const info = runtime({
        client: 'android-games',
        clientVersion: requiredVersion,
        clientBuild: requiredBuild,
        platform: 'android',
        platformVersion: '16',
    });
    const result = (0, index_1.validateClientEnvironment)(info);
    strict_1.default.equal(result.ok, true);
});
(0, node_test_1.default)('keeps accepting the legacy Apple client id during rollout', () => {
    const meta = (0, index_1.loadClientMeta)();
    const requiredVersion = meta.clients['all']?.minimumVersion ?? meta.version;
    const requiredBuild = meta.clients['all']?.minimumBuild ?? meta.build;
    const info = runtime({
        client: 'apple',
        clientVersion: requiredVersion,
        clientBuild: requiredBuild,
        platform: 'ios',
        platformVersion: '18.0',
    });
    const result = (0, index_1.validateClientEnvironment)(info);
    strict_1.default.equal(result.ok, true);
});
(0, node_test_1.default)('does not require a build floor for newer cli versions once the version is supported', () => {
    const meta = (0, index_1.loadClientMeta)();
    const requiredVersion = meta.clients['all']?.minimumVersion ?? meta.version;
    const info = runtime({
        client: 'cli',
        clientVersion: requiredVersion,
        clientBuild: 0,
        platform: 'macos',
        platformVersion: '14.0',
    });
    const result = (0, index_1.validateClientEnvironment)(info);
    strict_1.default.equal(result.ok, true);
});
(0, node_test_1.default)('returns failure when metadata is incomplete', () => {
    const info = runtime({ clientVersion: '', platformVersion: '' });
    const result = (0, index_1.validateClientEnvironment)(info);
    strict_1.default.equal(result.ok, false);
    if (!result.ok) {
        strict_1.default.equal(result.code, 'missing_client_metadata');
    }
});
