package com.xunhong.erp.turbo.biz.app.executor.cmd;

import com.xunhong.erp.turbo.api.biz.dto.cmd.OrderApproveCmd;
import com.xunhong.erp.turbo.api.biz.dto.vo.AuditVO;
import com.xunhong.erp.turbo.biz.app.assembler.AuditAssembler;
import com.xunhong.erp.turbo.biz.domain.entity.Audit;
import com.xunhong.erp.turbo.biz.domain.gateway.AuditGateway;
import com.xunhong.erp.turbo.biz.domain.gateway.OrderGateway;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author shenyifei
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class OrderApproveCmdExe {

	private final OrderGateway orderGateway;
	private final AuditGateway auditGateway;

	private final AuditAssembler auditAssembler;

	@Transactional
	public AuditVO execute(OrderApproveCmd orderApproveCmd) {
		Audit audit = auditGateway.approve(orderApproveCmd);
		orderGateway.approve(orderApproveCmd);

		return auditAssembler.toAuditVO(audit);
	}
}
