/**
 * Axelor Business Solutions
 *
 * Copyright (C) 2017 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.axelor.apps.bankpayment.service.config;

import com.axelor.apps.account.db.Account;
import com.axelor.apps.account.db.AccountConfig;
import com.axelor.apps.account.service.config.AccountConfigService;
import com.axelor.apps.bankpayment.exception.IExceptionMessage;
import com.axelor.apps.base.db.Sequence;
import com.axelor.apps.base.service.administration.GeneralServiceImpl;
import com.axelor.auth.db.User;
import com.axelor.exception.AxelorException;
import com.axelor.exception.db.IException;
import com.axelor.i18n.I18n;

public class AccountConfigBankPaymentService extends AccountConfigService  {


	public Account getExternalBankToBankAccount(AccountConfig accountConfig) throws AxelorException  {

		if(accountConfig.getExternalBankToBankAccount() == null)   {
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_EXTERNAL_BANK_TO_BANK_ACCOUNT),
					GeneralServiceImpl.EXCEPTION,accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}

		return accountConfig.getExternalBankToBankAccount();

	} 
	
	public Account getInternalBankToBankAccount(AccountConfig accountConfig) throws AxelorException  {

		if(accountConfig.getInternalBankToBankAccount() == null)   {
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_INTERNAL_BANK_TO_BANK_ACCOUNT),
					GeneralServiceImpl.EXCEPTION,accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}

		return accountConfig.getInternalBankToBankAccount();

	} 


    /******** Bank Order Sequences ********/
	public Sequence getSepaCreditTransSequence(AccountConfig accountConfig) throws AxelorException {
		if(accountConfig.getSepaCreditTransSequence() == null)   {
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_SEQUENCE_5), 
					GeneralServiceImpl.EXCEPTION, accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}

		return accountConfig.getSepaCreditTransSequence();
	}

	public Sequence getSepaDirectDebitSequence(AccountConfig accountConfig) throws AxelorException {
		if(accountConfig.getSepaDirectDebitSequence() == null)   {
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_SEQUENCE_6), 
					GeneralServiceImpl.EXCEPTION, accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}

		return accountConfig.getSepaDirectDebitSequence();
	}

	public Sequence getIntCreditTransSequence(AccountConfig accountConfig) throws AxelorException {
		if(accountConfig.getIntCreditTransSequence() == null)   {
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_SEQUENCE_7), 
					GeneralServiceImpl.EXCEPTION, accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}

		return accountConfig.getIntCreditTransSequence();
	}

	public Sequence getIntDirectDebitSequence(AccountConfig accountConfig) throws AxelorException {
		if(accountConfig.getIntDirectDebitSequence() == null)   {
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_SEQUENCE_8), 
					GeneralServiceImpl.EXCEPTION, accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}

		return accountConfig.getIntDirectDebitSequence();
	}
	
	public Sequence getNatTreasuryTransSequence(AccountConfig accountConfig) throws AxelorException {
		if(accountConfig.getNatTreasuryTransSequence() == null)   {
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_SEQUENCE_9), 
					GeneralServiceImpl.EXCEPTION, accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}

		return accountConfig.getNatTreasuryTransSequence();
	}
	
	public Sequence getIntTreasuryTransSequence(AccountConfig accountConfig) throws AxelorException {
		if(accountConfig.getIntTreasuryTransSequence() == null)   {
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_SEQUENCE_10), 
					GeneralServiceImpl.EXCEPTION, accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}

		return accountConfig.getIntTreasuryTransSequence();
	}
	
	public Sequence getOtherBankOrderSequence(AccountConfig accountConfig) throws AxelorException {
		if(accountConfig.getOtherBankOrderSequence() == null)   {
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_SEQUENCE_11), 
					GeneralServiceImpl.EXCEPTION, accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}

		return accountConfig.getOtherBankOrderSequence();
	}
	
	
	/******************************** BANK ORDERS *********************************************/
	public User getDefaultSignatoryUser(AccountConfig accountConfig) throws AxelorException  {
		if(accountConfig.getDefaultSignatoryUser() == null){
			throw new AxelorException(String.format(I18n.get(IExceptionMessage.ACCOUNT_CONFIG_41),
					GeneralServiceImpl.EXCEPTION,accountConfig.getCompany().getName()), IException.CONFIGURATION_ERROR);
		}
		return accountConfig.getDefaultSignatoryUser();
	}
	
}

@@ -4226,12 +4226,12 @@
 NCE_
-9
+10
 ),
- 
 %0A%09%09%09
@@ -4657,13 +4657,11 @@
 NCE_
-10
+9
 ),
- 
 %0A%09%09%09

fix sequence error message.