class ServiceEmitter {

    public void emitTypescriptInterface() {
        Set<String> endpointsToWarnAboutDuplicateNames = Sets.newHashSet();
        if (!this.settings.emitDuplicateJavaMethodNames()) {
            endpointsToWarnAboutDuplicateNames = getDuplicateEndpointNames();
        }

        writer.writeLine("");
        writer.writeLine("export interface " + settings.getSettings().addTypeNamePrefix + model.name() + " {");
        writer.increaseIndent();

        for (InnerServiceModel innerServiceModel : model.innerServiceModels()) {
            if (model.innerServiceModels().size() > 1) {
                writer.writeLine("");
                writer.writeLine("// endpoints for service class: " + innerServiceModel.name());
            }

            for (ServiceEndpointModel endpointModel: innerServiceModel.endpointModels()) {
                if (!endpointsToWarnAboutDuplicateNames.contains(endpointModel.endpointName())) {
                    String line = endpointModel.endpointName() + "(";
                    line += getEndpointParametersString(endpointModel);
                    line += String.format("): " + settings.genericEndpointReturnType(), endpointModel.tsReturnType().toString()) + ";";
                    writer.writeLine(line);
                }
            }
        }
        if (!endpointsToWarnAboutDuplicateNames.isEmpty()) {
            writer.writeLine("");
        }
        for (String endpointName : endpointsToWarnAboutDuplicateNames) {
            writer.writeLine(String.format("// WARNING: not creating method declaration, java service has multiple methods with the name %s", endpointName));
        }

        writer.decreaseIndent();
        writer.writeLine("}");
    }

}

class ServiceEmitterTest {

    private TypescriptServiceGeneratorConfiguration settings;
    private IndentedOutputWriter writer;
    private ByteArrayOutputStream stream;
    private ServiceClassParser serviceClassParser;

    @Test
    public void testMultipleClasses() {

        ServiceModel model = serviceClassParser.parseServiceClass(SimpleService1.class, settings, SimpleService2.class);
        ServiceEmitter serviceEmitter = new ServiceEmitter(model, settings, writer);
        serviceEmitter.emitTypescriptInterface();
        writer.close();
        String expectedOutput = "\n" +
"export interface SimpleService1 {\n" +
"\n" +
"    // endpoints for service class: SimpleService1\n" +
"    method1(): FooType<string>;\n" +
"\n" +
"    // endpoints for service class: SimpleService2\n" +
"    method2(): FooType<string>;\n" +
"}\n";
        assertEquals(expectedOutput, new String(stream.toByteArray()));
    }

}