import { BaseVisitor } from "@wapc/widl/ast";
import { expandType, isReference, capitalize } from "./helpers";
export class BuilderVisitor extends 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${capitalize(field.name.value)}(${field.name.value}: ${expandType(field.type, true, 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);
    }
}
//# sourceMappingURL=builder_visitor.js.map