package com.eactive.eai.rms.onl.manage.rule.layouttype;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eactive.eai.data.entity.onl.transformer.layout.LayoutTypeEntity;
import com.eactive.eai.rms.common.base.OnlBaseService;
import com.eactive.eai.rms.data.entity.onl.layout.LayoutTypeService;

/**
 * LayoutType 관련 Service 클래스입니다.
 */

@Service
@Transactional
public class LayoutTypeManService extends OnlBaseService {

	@Autowired
	private LayoutTypeManMapper layoutTypeMapper;

	@Autowired
	private LayoutTypeService layoutTypeService;

	public Page<LayoutTypeUI> selectList(Pageable pageable) {
		Page<LayoutTypeEntity> entityPage = layoutTypeService.findAll(pageable);
		return entityPage.map(layoutTypeMapper::toVo);
	}

	public LayoutTypeUI selectDetail(String loutptrnname) {
		LayoutTypeEntity entity = layoutTypeService.getById(loutptrnname);
		return layoutTypeMapper.toVo(entity);
	}

	public void update(LayoutTypeUI ui) throws Exception {
		LayoutTypeEntity entity = layoutTypeService.getById(ui.getLoutPtrnName());
		layoutTypeMapper.updateToEntity(ui, entity);
		layoutTypeService.save(entity);
	}

	public void insert(LayoutTypeUI ui) throws Exception {
		layoutTypeService.save(layoutTypeMapper.toEntity(ui));
	}

	public void delete(String loutptrnname) throws Exception {
		layoutTypeService.deleteById(loutptrnname);
	}
}
