class AccountDetailKeyController {

	@PostMapping("/_create")
	@ResponseStatus(HttpStatus.CREATED)
	public AccountDetailKeyResponse create(@RequestBody AccountDetailKeyRequest accountDetailKeyRequest,
			BindingResult errors,@RequestParam String tenantId) {
		if (errors.hasErrors()) {
			throw new CustomBindException(errors);
		}

		ModelMapper model = new ModelMapper();
		AccountDetailKeyResponse accountDetailKeyResponse = new AccountDetailKeyResponse();
		accountDetailKeyResponse.setResponseInfo(getResponseInfo(accountDetailKeyRequest.getRequestInfo()));
		List<AccountDetailKey> accountdetailkeys = new ArrayList<>();
		AccountDetailKey accountDetailKey;
		List<AccountDetailKeyContract> accountDetailKeyContracts = new ArrayList<>();
		AccountDetailKeyContract contract;

		accountDetailKeyRequest.getRequestInfo().setAction(Constants.ACTION_CREATE);

		for (AccountDetailKeyContract accountDetailKeyContract : accountDetailKeyRequest.getAccountDetailKeys()) {
			accountDetailKey = new AccountDetailKey();
			model.map(accountDetailKeyContract, accountDetailKey);
			accountDetailKey.setCreatedDate(new Date());
			accountDetailKey.setCreatedBy(accountDetailKeyRequest.getRequestInfo().getUserInfo());
			accountDetailKey.setLastModifiedBy(accountDetailKeyRequest.getRequestInfo().getUserInfo());
			accountdetailkeys.add(accountDetailKey);
		}

		accountdetailkeys = accountDetailKeyService.create(accountdetailkeys, errors,
				accountDetailKeyRequest.getRequestInfo());

		for (AccountDetailKey f : accountdetailkeys) {
			contract = new AccountDetailKeyContract();
			contract.setCreatedDate(new Date());
			model.map(f, contract);
			accountDetailKeyContracts.add(contract);
		}

		accountDetailKeyResponse.setAccountDetailKeys(accountDetailKeyContracts);

		return accountDetailKeyResponse;
	}

}