package cokr.xit.fims.levy.service.bean;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cokr.xit.foundation.component.AbstractServiceBean;
import cokr.xit.foundation.data.DataObject;

import cokr.xit.fims.levy.Rduct;
import cokr.xit.fims.levy.LevyQuery;
import cokr.xit.fims.levy.service.Levy02Service;

/**과태료 감경 대장 서비스 구현체.
 *
 * <p>상세 설명:
 *
 * <pre>
 * ============ 변경 이력 ============
 * 2023-08-30	JoJH 최초 작성
 * ================================
 * </pre>
 */
@Service("levy02Service")
public class Levy02ServiceBean extends AbstractServiceBean implements Levy02Service {

	/** 과태료 감경 대장 정보 Bean */
	@Resource(name = "levy02Bean")
	private Levy02Bean levy02Bean;

	@Override
	public List<DataObject> getRductList(LevyQuery req) {
		return levy02Bean.getRductList(req);
	}

	@Override
	public List<DataObject> getRducts(LevyQuery req) {
		return levy02Bean.getRducts(req);
	}

	@Override
	public DataObject getRductInfo(LevyQuery req) {
		if (req.getCallPurpose() == null) {
			req.setCallPurpose("view");
		}

		if (req.getCallPurpose().equals("create")) {
			return levy02Bean.getCrdnInfo(req);
		} else {
			return levy02Bean.getRductInfo(req);
		}
	}

	@Override
	public String createRduct(Rduct rduct) {
		return levy02Bean.createRduct(rduct);
	}

	@Override
	public String updateRduct(Rduct rduct) {
		return levy02Bean.updateRduct(rduct);
	}

	@Override
	public String removeRduct(Rduct rduct) {
		return levy02Bean.removeRduct(rduct);
	}

	@Override
	public String removeRducts(LevyQuery req) {
		// 변수 선언
		String retMessage = "";							// 처리 결과 메시지

		// 감경 IDs 건수를 확인하여 1건이하면.. 종료
		if (req.getRductIDs().length < 1 ) {
			retMessage = "작업 중 선택 자료가 존재하지 않습니다.";
			return retMessage;
		}

		// 감경 IDs 만큼 반복..
		for (int iLoop = 0; iLoop < req.getRductIDs().length; iLoop++) {
			Rduct rduct = new Rduct();

			rduct.setRductId(req.getRductIDs()[iLoop]);							// 감경 ID
			rduct.setDelRsn(req.getDelRsn());									// 삭제 사유

			// 과태료 감경 삭제 호출
			retMessage = levy02Bean.removeRduct(rduct);
			// 오류가 발생하였으면 종료..
			if (retMessage.contains("[F]")) {
				return retMessage;
			}
		}

		return retMessage;
	}

}
