"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const dna_schema_js_1 = require("./dna-schema.js");
// Helper: build a valid DNA object for testing
function validDNA() {
    return (0, dna_schema_js_1.fillDefaults)({
        id: 'test-id-123',
        createdAt: '2024-01-01T00:00:00.000Z',
        updatedAt: '2024-01-01T00:00:00.000Z',
        status: 'active',
        identity: {
            name: 'Ayşe',
            age: 24,
            nationality: 'Turkish',
            city: 'Istanbul',
            occupation: 'Model',
            personality_tags: ['friendly', 'outgoing'],
            mbti: 'ENFP',
            backstory: 'A young model from Istanbul.',
        },
    });
}
(0, vitest_1.describe)('validateHexColor', () => {
    (0, vitest_1.it)('accepts valid 6-digit hex colors', () => {
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('#FF0000')).toBe(true);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('#00ff00')).toBe(true);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('#1A2B3C')).toBe(true);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('#000000')).toBe(true);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('#FFFFFF')).toBe(true);
    });
    (0, vitest_1.it)('rejects invalid hex colors', () => {
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('')).toBe(false);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('FF0000')).toBe(false); // missing #
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('#FFF')).toBe(false); // 3-digit
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('#GGGGGG')).toBe(false); // invalid chars
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('#FF00001')).toBe(false); // 7 digits
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)('#FF000')).toBe(false); // 5 digits
    });
});
(0, vitest_1.describe)('validateMBTI', () => {
    (0, vitest_1.it)('has exactly 16 valid types', () => {
        (0, vitest_1.expect)(dna_schema_js_1.VALID_MBTI_TYPES).toHaveLength(16);
    });
    (0, vitest_1.it)('accepts all 16 valid MBTI types', () => {
        for (const t of dna_schema_js_1.VALID_MBTI_TYPES) {
            (0, vitest_1.expect)((0, dna_schema_js_1.validateMBTI)(t)).toBe(true);
        }
    });
    (0, vitest_1.it)('is case-insensitive', () => {
        (0, vitest_1.expect)((0, dna_schema_js_1.validateMBTI)('enfp')).toBe(true);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateMBTI)('Intj')).toBe(true);
    });
    (0, vitest_1.it)('rejects invalid MBTI types', () => {
        (0, vitest_1.expect)((0, dna_schema_js_1.validateMBTI)('XXXX')).toBe(false);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateMBTI)('')).toBe(false);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateMBTI)('ENF')).toBe(false);
    });
});
(0, vitest_1.describe)('validateDNA', () => {
    (0, vitest_1.it)('returns valid for a complete DNA object', () => {
        const result = (0, dna_schema_js_1.validateDNA)(validDNA());
        (0, vitest_1.expect)(result.valid).toBe(true);
        (0, vitest_1.expect)(result.errors).toHaveLength(0);
    });
    (0, vitest_1.it)('rejects null/undefined/non-object', () => {
        (0, vitest_1.expect)((0, dna_schema_js_1.validateDNA)(null).valid).toBe(false);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateDNA)(undefined).valid).toBe(false);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateDNA)('string').valid).toBe(false);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateDNA)(42).valid).toBe(false);
    });
    (0, vitest_1.it)('reports missing top-level fields', () => {
        const result = (0, dna_schema_js_1.validateDNA)({});
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('id'))).toBe(true);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('status'))).toBe(true);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('identity'))).toBe(true);
    });
    (0, vitest_1.it)('validates identity.mbti', () => {
        const dna = validDNA();
        dna.identity.mbti = 'INVALID';
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('mbti'))).toBe(true);
    });
    (0, vitest_1.it)('validates height_cm range', () => {
        const dna = validDNA();
        dna.physicalMeasurements.height_cm = 10; // below 50
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('height_cm'))).toBe(true);
    });
    (0, vitest_1.it)('validates weight_kg range', () => {
        const dna = validDNA();
        dna.physicalMeasurements.weight_kg = 500; // above 300
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('weight_kg'))).toBe(true);
    });
    (0, vitest_1.it)('validates measurement ranges', () => {
        const dna = validDNA();
        dna.physicalMeasurements.measurements.bust = 10; // below 50
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('bust'))).toBe(true);
    });
    (0, vitest_1.it)('validates HEX colors in skinMap', () => {
        const dna = validDNA();
        dna.skinMap.base = 'not-hex';
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('skinMap.base'))).toBe(true);
    });
    (0, vitest_1.it)('validates HEX colors in hairDNA', () => {
        const dna = validDNA();
        dna.hairDNA.root_color = 'bad';
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('hairDNA.root_color'))).toBe(true);
    });
    (0, vitest_1.it)('validates HEX colors in makeupStyle.colors', () => {
        const dna = validDNA();
        dna.makeupStyle.colors.primary = 'nope';
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('makeupStyle.colors.primary'))).toBe(true);
    });
    (0, vitest_1.it)('validates HEX colors in fashionStyle.main_colors', () => {
        const dna = validDNA();
        dna.fashionStyle.main_colors = ['#000000', 'invalid'];
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('fashionStyle.main_colors'))).toBe(true);
    });
    (0, vitest_1.it)('validates required string fields in technicalSettings', () => {
        const dna = validDNA();
        dna.technicalSettings.camera_body = '';
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(false);
        (0, vitest_1.expect)(result.errors.some(e => e.includes('technicalSettings.camera_body'))).toBe(true);
    });
    (0, vitest_1.it)('validates all 11 components are checked', () => {
        // An empty object should report errors for all 11 sections
        const result = (0, dna_schema_js_1.validateDNA)({
            id: 'x', createdAt: 'x', updatedAt: 'x', status: 'active',
        });
        (0, vitest_1.expect)(result.valid).toBe(false);
        const sections = [
            'identity', 'physicalMeasurements', 'skinMap', 'faceAnatomy',
            'hairDNA', 'bodyBiometrics', 'profileView', 'expressionMotion',
            'makeupStyle', 'fashionStyle', 'technicalSettings',
        ];
        for (const s of sections) {
            (0, vitest_1.expect)(result.errors.some(e => e.includes(s))).toBe(true);
        }
    });
});
(0, vitest_1.describe)('fillDefaults', () => {
    (0, vitest_1.it)('returns a complete CharacterDNA from empty partial', () => {
        const dna = (0, dna_schema_js_1.fillDefaults)({});
        const result = (0, dna_schema_js_1.validateDNA)(dna);
        (0, vitest_1.expect)(result.valid).toBe(true);
        (0, vitest_1.expect)(result.errors).toHaveLength(0);
    });
    (0, vitest_1.it)('generates an id if not provided', () => {
        const dna = (0, dna_schema_js_1.fillDefaults)({});
        (0, vitest_1.expect)(dna.id).toBeTruthy();
        (0, vitest_1.expect)(typeof dna.id).toBe('string');
    });
    (0, vitest_1.it)('preserves provided values', () => {
        const dna = (0, dna_schema_js_1.fillDefaults)({
            identity: {
                name: 'Custom Name',
                age: 30,
                nationality: 'German',
                city: 'Berlin',
                occupation: 'Engineer',
                personality_tags: ['smart'],
                mbti: 'INTJ',
                backstory: 'A story',
            },
        });
        (0, vitest_1.expect)(dna.identity.name).toBe('Custom Name');
        (0, vitest_1.expect)(dna.identity.age).toBe(30);
        (0, vitest_1.expect)(dna.identity.nationality).toBe('German');
    });
    (0, vitest_1.it)('fills default status as creating', () => {
        const dna = (0, dna_schema_js_1.fillDefaults)({});
        (0, vitest_1.expect)(dna.status).toBe('creating');
    });
    (0, vitest_1.it)('fills default HEX colors that pass validation', () => {
        const dna = (0, dna_schema_js_1.fillDefaults)({});
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)(dna.skinMap.base)).toBe(true);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)(dna.skinMap.shadow)).toBe(true);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)(dna.skinMap.highlight)).toBe(true);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)(dna.hairDNA.root_color)).toBe(true);
        (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)(dna.makeupStyle.colors.primary)).toBe(true);
        for (const c of dna.fashionStyle.main_colors) {
            (0, vitest_1.expect)((0, dna_schema_js_1.validateHexColor)(c)).toBe(true);
        }
    });
    (0, vitest_1.it)('fills default MBTI that passes validation', () => {
        const dna = (0, dna_schema_js_1.fillDefaults)({});
        (0, vitest_1.expect)((0, dna_schema_js_1.validateMBTI)(dna.identity.mbti)).toBe(true);
    });
    (0, vitest_1.it)('fills default physical measurements within valid ranges', () => {
        const dna = (0, dna_schema_js_1.fillDefaults)({});
        (0, vitest_1.expect)(dna.physicalMeasurements.height_cm).toBeGreaterThanOrEqual(50);
        (0, vitest_1.expect)(dna.physicalMeasurements.height_cm).toBeLessThanOrEqual(250);
        (0, vitest_1.expect)(dna.physicalMeasurements.weight_kg).toBeGreaterThanOrEqual(20);
        (0, vitest_1.expect)(dna.physicalMeasurements.weight_kg).toBeLessThanOrEqual(300);
    });
});
//# sourceMappingURL=dna-schema.test.js.map