class AccountCodePurposeController {

	@PostMapping("_create")
	@ResponseStatus(HttpStatus.OK)
	public AccountCodePurposeContractResponse create(
			@RequestBody @Valid AccountCodePurposeContractRequest accountCodePurposeContractRequest,
			BindingResult errors) {
		accountCodePurposeService.validate(accountCodePurposeContractRequest, "create", errors);
		if (errors.hasErrors()) {
			throw new CustomBindException(errors);
		}
		accountCodePurposeContractRequest.getRequestInfo().setAction("create");
		accountCodePurposeService.fetchRelatedContracts(accountCodePurposeContractRequest);
		accountCodePurposeService.push(accountCodePurposeContractRequest);
		AccountCodePurposeContractResponse accountCodePurposeContractResponse = new AccountCodePurposeContractResponse();
		accountCodePurposeContractResponse.setAccountCodePurposes(new ArrayList<AccountCodePurposeContract>());
		if (accountCodePurposeContractRequest.getAccountCodePurposes() != null
				&& !accountCodePurposeContractRequest.getAccountCodePurposes().isEmpty()) {
			for (AccountCodePurposeContract accountCodePurposeContract : accountCodePurposeContractRequest
					.getAccountCodePurposes()) {

				accountCodePurposeContractResponse.getAccountCodePurposes().add(accountCodePurposeContract);
			}
		} else if (accountCodePurposeContractRequest.getAccountCodePurpose() != null) {
			accountCodePurposeContractResponse
					.setAccountCodePurpose(accountCodePurposeContractRequest.getAccountCodePurpose());
		}
		accountCodePurposeContractResponse
				.setResponseInfo(getResponseInfo(accountCodePurposeContractRequest.getRequestInfo()));
		accountCodePurposeContractResponse.getResponseInfo().setStatus(HttpStatus.OK.toString());
		return accountCodePurposeContractResponse;
	}

}