class ChartOfAccountDetailController {

	@PostMapping("/_update")
	@ResponseStatus(HttpStatus.CREATED)
	public ChartOfAccountDetailResponse update(@RequestBody ChartOfAccountDetailRequest chartOfAccountDetailRequest,
			BindingResult errors,@RequestParam String tenantId) {

		if (errors.hasErrors()) {
			throw new CustomBindException(errors);
		}
		chartOfAccountDetailRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE);
		ModelMapper model = new ModelMapper();
		ChartOfAccountDetailResponse chartOfAccountDetailResponse = new ChartOfAccountDetailResponse();
		List<ChartOfAccountDetail> chartofaccountdetails = new ArrayList<>();
		chartOfAccountDetailResponse.setResponseInfo(getResponseInfo(chartOfAccountDetailRequest.getRequestInfo()));
		ChartOfAccountDetail chartOfAccountDetail;
		ChartOfAccountDetailContract contract;
		List<ChartOfAccountDetailContract> chartOfAccountDetailContracts = new ArrayList<>();

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

		chartofaccountdetails = chartOfAccountDetailService.update(chartofaccountdetails, errors);

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

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

		return chartOfAccountDetailResponse;
	}

}