/*
 * Copyright 2020 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.b2international.snowowl.core.request.io;

import javax.annotation.OverridingMethodsMustInvokeSuper;

import com.b2international.snowowl.core.attachments.Attachment;
import com.b2international.snowowl.core.domain.TransactionContext;
import com.b2international.snowowl.core.events.AsyncRequest;
import com.b2international.snowowl.core.events.BaseRequestBuilder;
import com.b2international.snowowl.core.events.Request;
import com.b2international.snowowl.core.request.CommitResult;
import com.b2international.snowowl.core.request.RepositoryCommitRequestBuilder;

/**
 * @since 7.12
 * @param <T>
 */
public abstract class ImportRequestBuilder<T extends ImportRequestBuilder<T>> 
		extends BaseRequestBuilder<T, TransactionContext, ImportResponse> {

	private final Attachment attachment;
	
	public ImportRequestBuilder(Attachment attachment) {
		this.attachment = attachment;
	}
	
	@Override
	protected final Request<TransactionContext, ImportResponse> doBuild() {
		ImportRequest req = create();
		init(req);
		return req;
	}

	@OverridingMethodsMustInvokeSuper
	protected void init(ImportRequest req) {
		req.setAttachment(attachment);
	}

	protected abstract ImportRequest create();
	
	public AsyncRequest<CommitResult> build(String repositoryId, String branch) {
		return new RepositoryCommitRequestBuilder()
				.setBody(build())
				.setCommitComment(String.format("Imported components from source file '%s'", attachment.getFileName()))
				.build(repositoryId, branch);
	} 
	
}

@@ -1185,16 +1185,75 @@
 Builder;
+%0Aimport com.b2international.snowowl.core.uri.CodeSystemURI;
 %0A%0A/**%0A *
@@ -1867,24 +1867,424 @@
 create();%0A%09%0A
+%09public AsyncRequest%3CCommitResult%3E build(String codeSystemUri) %7B%0A%09%09return build(new CodeSystemURI(codeSystemUri));%0A%09%7D%0A%09%0A%09public AsyncRequest%3CCommitResult%3E build(CodeSystemURI codeSystemUri) %7B%0A%09%09return new RepositoryCommitRequestBuilder()%0A%09%09%09%09.setBody(build())%0A%09%09%09%09.setCommitComment(String.format(%22Imported components from source file '%25s'%22, attachment.getFileName()))%0A%09%09%09%09.build(codeSystemUri);%0A%09%7D%0A%09%0A
 %09public Asyn

add CodeSystemURI based build methods