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

import com.xunhong.erp.turbo.api.user.dto.cmd.EmployeeDisableCmd;
import com.xunhong.erp.turbo.api.user.dto.cmd.UserDisableCmd;
import com.xunhong.erp.turbo.api.user.dto.vo.EmployeeVO;
import com.xunhong.erp.turbo.user.app.assembler.EmployeeAssembler;
import com.xunhong.erp.turbo.user.domain.entity.Employee;
import com.xunhong.erp.turbo.user.domain.gateway.EmployeeGateway;
import com.xunhong.erp.turbo.user.domain.gateway.UserGateway;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author shenyifei
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class EmployeeDisableCmdExe {
	private final EmployeeGateway employeeGateway;
	private final UserGateway userGateway;

	private final EmployeeAssembler employeeAssembler;

	public EmployeeVO execute(EmployeeDisableCmd employeeDisableCmd) {
		Employee employee = employeeGateway.disable(employeeDisableCmd);

		UserDisableCmd userDisableCmd = new UserDisableCmd();
		userDisableCmd.setUserId(employee.getUserId());
		userGateway.disable(userDisableCmd);

		return employeeAssembler.toEmployeeVO(employee);
	}
}
