class AccountCodePurposeController {

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

		ModelMapper model = new ModelMapper();
		AccountCodePurposeResponse accountCodePurposeResponse = new AccountCodePurposeResponse();
		accountCodePurposeResponse.setResponseInfo(getResponseInfo(accountCodePurposeRequest.getRequestInfo()));
		List<AccountCodePurpose> accountcodepurposes = new ArrayList<>();
		AccountCodePurpose accountCodePurpose;
		List<AccountCodePurposeContract> accountCodePurposeContracts = new ArrayList<>();
		AccountCodePurposeContract contract;

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

		for (AccountCodePurposeContract accountCodePurposeContract : accountCodePurposeRequest
				.getAccountCodePurposes()) {
			accountCodePurpose = new AccountCodePurpose();
			model.map(accountCodePurposeContract, accountCodePurpose);
			accountCodePurpose.setCreatedDate(new Date());
			accountCodePurpose.setCreatedBy(accountCodePurposeRequest.getRequestInfo().getUserInfo());
			accountCodePurpose.setLastModifiedBy(accountCodePurposeRequest.getRequestInfo().getUserInfo());
			accountcodepurposes.add(accountCodePurpose);
		}

		accountcodepurposes = accountCodePurposeService.create(accountcodepurposes, errors,
				accountCodePurposeRequest.getRequestInfo());

		for (AccountCodePurpose f : accountcodepurposes) {
			contract = new AccountCodePurposeContract();
			contract.setCreatedDate(new Date());
			model.map(f, contract);
			accountCodePurposeContracts.add(contract);
		}

		accountCodePurposeResponse.setAccountCodePurposes(accountCodePurposeContracts);

		return accountCodePurposeResponse;
	}

}