"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BuilderVisitor = void 0;
const ast_1 = require("@wapc/widl/ast");
const helpers_1 = require("./helpers");
class BuilderVisitor extends ast_1.BaseVisitor {
    constructor(writer) {
        super(writer);
    }
    visitObjectBefore(context) {
        super.triggerObjectBefore(context);
        const className = context.object.name.value;
        this.write(`export class ${className}Builder {
  instance: ${className} = new ${className}();\n`);
    }
    visitObjectField(context) {
        const className = context.object.name.value;
        const field = context.field;
        this.write(`\n`);
        this.write(`with${helpers_1.capitalize(field.name.value)}(${field.name.value}: ${helpers_1.expandType(field.type, true, helpers_1.isReference(field.annotations))}): ${className}Builder {
    this.instance.${field.name.value} = ${field.name.value};
    return this;
  }\n`);
        super.triggerObjectField(context);
    }
    visitObjectFieldsAfter(context) {
        this.write(`\n`);
        this.write(`  build(): ${context.object.name.value} {
      return this.instance;
    }`);
        super.triggerObjectFieldsAfter(context);
    }
    visitObjectAfter(context) {
        this.write(`}\n\n`);
        super.triggerObjectAfter(context);
    }
}
exports.BuilderVisitor = BuilderVisitor;
//# sourceMappingURL=builder_visitor.js.map