"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeDNA = serializeDNA;
exports.parseDNA = parseDNA;
exports.cloneDNA = cloneDNA;
const dna_schema_js_1 = require("./dna-schema.js");
/**
 * Serialize a CharacterDNA object to a JSON string.
 * Uses 2-space indentation for readability.
 */
function serializeDNA(dna) {
    return JSON.stringify(dna, null, 2);
}
/**
 * Parse a JSON string into a CharacterDNA object with validation.
 * Throws if the JSON is invalid or doesn't match the CharacterDNA schema.
 */
function parseDNA(json) {
    let parsed;
    try {
        parsed = JSON.parse(json);
    }
    catch {
        throw new Error('Invalid JSON: failed to parse input string');
    }
    const result = (0, dna_schema_js_1.validateDNA)(parsed);
    if (!result.valid) {
        throw new Error(`Invalid CharacterDNA: ${result.errors.join('; ')}`);
    }
    return parsed;
}
/**
 * Deep clone a CharacterDNA object via serialize/parse round-trip.
 * Guarantees a completely independent copy.
 */
function cloneDNA(dna) {
    return JSON.parse(JSON.stringify(dna));
}
//# sourceMappingURL=serializer.js.map