package kr.co.jinwoosi.clfd.conts.lang.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import kr.co.jinwoosi.clfd.conts.lang.mapper.LangMapper;
import kr.co.jinwoosi.clfd.conts.lang.model.Lang;
import kr.co.jinwoosi.clfd.conts.lang.model.LangSearch;
import kr.co.jinwoosi.clfd.conts.lang.service.LangService;
import kr.co.jinwoosi.clfd.framework.base.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import kr.co.jinwoosi.clfd.framework.cd.model.CdDtl;
import kr.co.jinwoosi.clfd.framework.cd.service.CdDtlService;

@Service(value="langService")
public class LangServiceImpl extends BaseServiceImpl<Lang, LangSearch, LangMapper> implements LangService {

	@Resource (name="cdDtlService")
	private CdDtlService cdDtlService;
	
	@Override
	@Resource (name="langMapper")
	protected void setMapper (LangMapper mapper) {
		super.setMapper (mapper);
	}
	
	
	@Override
	public Lang select(LangSearch s) {
		Lang lang = super.select(s);
		
		List<CdDtl> cdDtlList = cdDtlService.selectJson("lang");
		for(CdDtl cdDtl : cdDtlList) {
			if(cdDtl.getCdDtlId().equals(lang.getLangTp())) {
				lang.setLangTpCd(cdDtl);
				break;
			}
		}
		
		return lang;
	}

	@Override
	public List<Lang> selectList(LangSearch s) {
		List<Lang> result = new ArrayList<Lang>();
		List<Lang> langList = super.selectList(s);
		
		List<CdDtl> cdDtlList = cdDtlService.selectJson("lang");
		
		for(Lang lang : langList) {
			for(CdDtl cdDtl : cdDtlList) {
				if(cdDtl.getCdDtlId().equals(lang.getLangTp())) {
					lang.setLangTpCd(cdDtl);
					break;
				}
			}
			
			result.add(lang);
		}
		return result;
	}

	@Override
	public int checkIdDuplicate (Lang s) {
		return mapper.checkIdDuplicate (s);
	}
}
