class AccountDetailTypeController {

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

		ModelMapper model = new ModelMapper();
		AccountDetailTypeResponse accountDetailTypeResponse = new AccountDetailTypeResponse();
		accountDetailTypeResponse.setResponseInfo(getResponseInfo(accountDetailTypeRequest.getRequestInfo()));
		List<AccountDetailType> accountdetailtypes = new ArrayList<>();
		AccountDetailType accountDetailType;
		List<AccountDetailTypeContract> accountDetailTypeContracts = new ArrayList<>();
		AccountDetailTypeContract contract;

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

		for (AccountDetailTypeContract accountDetailTypeContract : accountDetailTypeRequest.getAccountDetailTypes()) {
			accountDetailType = new AccountDetailType();
			model.map(accountDetailTypeContract, accountDetailType);
			accountDetailType.setCreatedDate(new Date());
			accountDetailType.setCreatedBy(accountDetailTypeRequest.getRequestInfo().getUserInfo());
			accountDetailType.setLastModifiedBy(accountDetailTypeRequest.getRequestInfo().getUserInfo());
			accountdetailtypes.add(accountDetailType);
		}

		accountdetailtypes = accountDetailTypeService.create(accountdetailtypes, errors,
				accountDetailTypeRequest.getRequestInfo());

		for (AccountDetailType f : accountdetailtypes) {
			contract = new AccountDetailTypeContract();
			contract.setCreatedDate(new Date());
			model.map(f, contract);
			accountDetailTypeContracts.add(contract);
		}

		accountDetailTypeResponse.setAccountDetailTypes(accountDetailTypeContracts);

		return accountDetailTypeResponse;
	}

}