"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 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(`#[derive(Debug, PartialEq, Deserialize, Serialize, Default, Clone)]
pub struct ${context.object.name.value} {\n`);
    }
    visitObjectField(context) {
        const field = context.field;
        const expandedType = helpers_1.expandType(field.type, undefined, true, helpers_1.isReference(field.annotations));
        this.write(utils_1.formatComment("  /// ", field.description));
        if (expandedType.indexOf("Vec<u8>") != -1) {
            this.write(`#[serde(with = "serde_bytes")]\n`);
        }
        this.write(`\t#[serde(rename = "${field.name.value}")]
      \tpub ${helpers_1.fieldName(field.name.value)}: ${expandedType},\n`);
        super.triggerObjectField(context);
    }
    visitObjectAfter(context) {
        this.write(`}\n\n`);
    }
}
exports.StructVisitor = StructVisitor;
//# sourceMappingURL=struct_visitor.js.map