"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StructVisitor = void 0;
const ast_1 = require("@wapc/widl/ast");
const helpers_1 = require("./helpers");
const decoder_visitor_1 = require("./decoder_visitor");
const encoder_visitor_1 = require("./encoder_visitor");
const utils_1 = require("../utils");
class StructVisitor extends ast_1.BaseVisitor {
    constructor(writer) {
        super(writer);
    }
    visitObjectBefore(context) {
        super.triggerObjectBefore(context);
        this.write(utils_1.formatComment("    // ", context.object.description));
        this.write(`type ${context.object.name.value} struct {\n`);
    }
    visitObjectField(context) {
        const field = context.field;
        this.write(utils_1.formatComment("    // ", field.description));
        this.write(`\t${helpers_1.fieldName(field.name.value)} ${helpers_1.expandType(field.type, undefined, true, helpers_1.isReference(field.annotations))}\n`);
        super.triggerObjectField(context);
    }
    visitObjectAfter(context) {
        this.write(`}\n\n`);
        super.triggerObjectAfter(context);
        const object = context.object;
        const decoder = new decoder_visitor_1.DecoderVisitor(this.writer);
        object.accept(context, decoder);
        const encoder = new encoder_visitor_1.EncoderVisitor(this.writer);
        object.accept(context, encoder);
        this.write(`\n`);
    }
}
exports.StructVisitor = StructVisitor;
//# sourceMappingURL=struct_visitor.js.map