package com.xunhong.erp.turbo.infra.app.service;

import com.alicp.jetcache.anno.Cached;
import com.xunhong.erp.turbo.api.infra.api.ChannelServiceI;
import com.xunhong.erp.turbo.api.infra.dto.cmd.ChannelCreateCmd;
import com.xunhong.erp.turbo.api.infra.dto.cmd.ChannelDestroyCmd;
import com.xunhong.erp.turbo.api.infra.dto.cmd.ChannelUpdateCmd;
import com.xunhong.erp.turbo.api.infra.dto.qry.ChannelPageQry;
import com.xunhong.erp.turbo.api.infra.dto.qry.ChannelShowQry;
import com.xunhong.erp.turbo.api.infra.dto.vo.ChannelVO;
import com.xunhong.erp.turbo.base.dto.PageDTO;
import com.xunhong.erp.turbo.infra.app.executor.cmd.ChannelCreateCmdExe;
import com.xunhong.erp.turbo.infra.app.executor.cmd.ChannelDestroyCmdExe;
import com.xunhong.erp.turbo.infra.app.executor.cmd.ChannelUpdateCmdExe;
import com.xunhong.erp.turbo.infra.app.executor.query.ChannelPageQryExe;
import com.xunhong.erp.turbo.infra.app.executor.query.ChannelShowQryExe;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;


@Slf4j
@Service
@DubboService(interfaceClass = ChannelServiceI.class, version = "1.0.0")
@RequiredArgsConstructor
public class ChannelServiceImpl implements ChannelServiceI {
	private final ChannelPageQryExe channelPageQryExe;
	private final ChannelCreateCmdExe channelCreateCmdExe;
	private final ChannelShowQryExe channelShowQryExe;
	private final ChannelUpdateCmdExe channelUpdateCmdExe;
	private final ChannelDestroyCmdExe channelDestroyCmdExe;

	@Override
	public PageDTO<ChannelVO> page(ChannelPageQry channelPageQry) {
		return PageDTO.of(channelPageQryExe.execute(channelPageQry));
	}

	@Override
	public ChannelVO create(ChannelCreateCmd channelCreateCmd) {
		return channelCreateCmdExe.execute(channelCreateCmd);
	}

	@Override
	@Cached(name = ":channel:id:", key = "#channelShowQry.channelId")
	public ChannelVO show(ChannelShowQry channelShowQry) {
		return channelShowQryExe.execute(channelShowQry);
	}

	@Override
	public ChannelVO update(ChannelUpdateCmd channelUpdateCmd) {
		return channelUpdateCmdExe.execute(channelUpdateCmd);
	}

	@Override
	public void destroy(ChannelDestroyCmd channelDestroyCmd) {
		channelDestroyCmdExe.execute(channelDestroyCmd);
	}
}
