class ChartOfAccountDetailController {

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

		ModelMapper model = new ModelMapper();
		ChartOfAccountDetailResponse chartOfAccountDetailResponse = new ChartOfAccountDetailResponse();
		chartOfAccountDetailResponse.setResponseInfo(getResponseInfo(chartOfAccountDetailRequest.getRequestInfo()));
		List<ChartOfAccountDetail> chartofaccountdetails = new ArrayList<>();
		ChartOfAccountDetail chartOfAccountDetail;
		List<ChartOfAccountDetailContract> chartOfAccountDetailContracts = new ArrayList<>();
		ChartOfAccountDetailContract contract;

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

		for (ChartOfAccountDetailContract chartOfAccountDetailContract : chartOfAccountDetailRequest
				.getChartOfAccountDetails()) {
			chartOfAccountDetail = new ChartOfAccountDetail();
			model.map(chartOfAccountDetailContract, chartOfAccountDetail);
			chartOfAccountDetail.setCreatedDate(new Date());
			chartOfAccountDetail.setCreatedBy(chartOfAccountDetailRequest.getRequestInfo().getUserInfo());
			chartOfAccountDetail.setLastModifiedBy(chartOfAccountDetailRequest.getRequestInfo().getUserInfo());
			chartofaccountdetails.add(chartOfAccountDetail);
		}

		chartofaccountdetails = chartOfAccountDetailService.add(chartofaccountdetails, errors);

		for (ChartOfAccountDetail f : chartofaccountdetails) {
			contract = new ChartOfAccountDetailContract();
			contract.setCreatedDate(new Date());
			model.map(f, contract);
			chartOfAccountDetailContracts.add(contract);
		}

		chartOfAccountDetailRequest.setChartOfAccountDetails(chartOfAccountDetailContracts);
		chartOfAccountDetailService.addToQue(chartOfAccountDetailRequest);
		chartOfAccountDetailResponse.setChartOfAccountDetails(chartOfAccountDetailContracts);

		return chartOfAccountDetailResponse;
	}

}