package com.keao.edu.cms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.keao.edu.cms.dal.dao.HelpCenterCatalogDao;
import com.keao.edu.cms.dal.entity.HelpCenterCatalog;
import com.keao.edu.cms.service.HelpCenterCatalogService;
import com.keao.edu.cms.service.HelpCenterContentService;
import com.keao.edu.common.dal.BaseDAO;
import com.keao.edu.common.service.impl.BaseServiceImpl;

@Service
public class HelpCenterCatalogServiceImpl extends BaseServiceImpl<Integer, HelpCenterCatalog> implements HelpCenterCatalogService {

	@Autowired
	private HelpCenterCatalogDao helpCenterCatalogDao;

	@Autowired
	private HelpCenterContentService helpCenterContentService;

	@Override
	public BaseDAO<Integer, HelpCenterCatalog> getDAO() {

		return helpCenterCatalogDao;
	}

	@Override
	public List<HelpCenterCatalog> queryByParentId(Integer parentId, Integer status) {

		List<HelpCenterCatalog> dataList = helpCenterCatalogDao.queryByParentId(parentId, status);
		if (dataList != null) {
			for (HelpCenterCatalog sub : dataList) {
				sub.setChildren(queryByParentId(sub.getId(), status));
			}
		}
		return dataList;
	}

	public boolean updateCatalog(HelpCenterCatalog catalog) {
		return helpCenterCatalogDao.update(catalog) > 0 && helpCenterContentService.updateContentByCatalog(catalog.getId(), catalog.getStatus());
	}

	@Override
	public boolean deleteCatalog(Integer id) {
		return helpCenterCatalogDao.delete(id) > 0 && helpCenterContentService.deleteContentByCatalog(id);
	}

}
