/*
 * This file is a part of EpnTAPClient.
 * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
 * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
 * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
 *
 * This program is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
 * the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

package eu.omp.irap.vespa.epntapclient.epntap.service;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import eu.omp.irap.vespa.votable.utils.StringJoiner;

/**
 * @author N. Jourdane
 */
public class ServicesList {

	/** The logger for the class ServicesList. */
	private static final Logger LOGGER = Logger.getLogger(ServicesList.class.getName());

	/** The list of table names entered in the custom table name field. */
	private List<String> customTableNames;

	/** The list of target URLs entered in the custom target URL field. */
	private List<String> customTargetUrls;

	/** The list of table names selected in the services table. */
	private List<String> selectedTableNames;

	/** The list of target URLs selected in the services table. */
	private List<String> selectedTargetUrls;


	/**
	 * Constructor of LightServicesList
	 */
	public ServicesList() {
		customTableNames = new ArrayList<>();
		customTargetUrls = new ArrayList<>();
		selectedTableNames = new ArrayList<>();
		selectedTargetUrls = new ArrayList<>();
	}

	/** @return The numbers of services (custom + selected) */
	public int getNbServices() {
		return customTargetUrls.size() + selectedTargetUrls.size();
	}

	/**
	 * @return the tableName
	 */
	public List<String> getTableNames() {
		List<String> tableNames = selectedTableNames;
		tableNames.addAll(customTableNames);
		return tableNames;
	}

	/**
	 * @return the targetUrl
	 */
	public List<String> getTargetUrls() {
		List<String> targetUrls = selectedTargetUrls;
		targetUrls.addAll(customTargetUrls);
		return targetUrls;
	}

	/**
	 * Update the services (table name and target URLs) entered in the custom services fields.
	 *
	 * @param customTableNamesToAdd The list of the table names to update.
	 * @param customTargetUrlsToAdd The list of the target URLs to update.
	 */
	public void updateCustomServices(List<String> customTableNamesToAdd,
			List<String> customTargetUrlsToAdd) {
		customTableNames = customTableNamesToAdd;
		customTargetUrls = customTargetUrlsToAdd;
		LOGGER.info("Updated custom tables names: " + StringJoiner.join(customTableNames));
		LOGGER.info("Updated custom services URLs: " + StringJoiner.join(customTargetUrls));
	}

	/**
	 * Update the services (table name and target URLs) selected in the services table.
	 *
	 * @param selectedTableNamesToAdd The list of the table names to update.
	 * @param selectedTargetUrlsToAdd The list of the target URLs to update.
	 */
	public void updateSelectedServices(List<String> selectedTableNamesToAdd,
			List<String> selectedTargetUrlsToAdd) {
		selectedTableNames = selectedTableNamesToAdd;
		selectedTargetUrls = selectedTargetUrlsToAdd;
		LOGGER.info("Updated selected tables names: " + StringJoiner.join(selectedTableNames));
		LOGGER.info("Updated selected services URLs: " + StringJoiner.join(selectedTargetUrls));
	}
}
