/*-
 * ~~~~~~licensing~~~~~~
 * artifact-management
 * ==========
 * Copyright (C) 2020 - 2021 EmDev LLC
 * ==========
 * 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.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.platform.core.artifact.repository.impl.remote;

import java.net.MalformedURLException;
import java.net.URL;

import ru.entaxy.platform.core.artifact.repository.impl.RepositoryDescriptor;

public class RemoteRepositoryDescriptor {

	String type = "nexus";
	
	String host;
	String hostSuffix;
	String username;
	String password;
	String repositoryPath;
	
	public RemoteRepositoryDescriptor(RepositoryDescriptor repositoryDescriptor) throws MalformedURLException {
		String repositoryUrl = repositoryDescriptor.getRemotes().trim();
		URL url = new URL(repositoryUrl);
		this.host = url.getProtocol() + "://" + url.getHost();
		if (url.getPort()>0)
			this.host += ":" + url.getPort();
		this.hostSuffix = repositoryDescriptor.getRemoteHostSuffix();
		this.repositoryPath = url.getPath();
		this.username = repositoryDescriptor.getUsername();
		this.password = repositoryDescriptor.getPassword();
	}

	public String getType() {
		return type;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRepositoryPath() {
		return repositoryPath;
	}

	public void setRepositoryPath(String repositoryName) {
		this.repositoryPath = repositoryName;
	}

	public String getHostSuffix() {
		return hostSuffix;
	}

	public void setHostSuffix(String hostSuffix) {
		this.hostSuffix = hostSuffix;
	} 
	
}
