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

import com.xunhong.erp.turbo.api.rbac.dto.cmd.UserRoleCreateCmd;
import com.xunhong.erp.turbo.api.rbac.dto.vo.UserRoleVO;
import com.xunhong.erp.turbo.rbac.app.assembler.UserRoleAssembler;
import com.xunhong.erp.turbo.rbac.domain.entity.UserRole;
import com.xunhong.erp.turbo.rbac.domain.gateway.UserRoleGateway;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
@RequiredArgsConstructor
public class UserRoleCreateCmdExe {

	private final UserRoleGateway userRoleGateway;
	private final UserRoleAssembler userRoleAssembler;

	public List<UserRoleVO> execute(UserRoleCreateCmd userRoleCreateCmd) {
		List<UserRole> userRoleList = userRoleGateway.create(userRoleCreateCmd);
		return userRoleList.stream().map(userRoleAssembler::toUserRoleVO).collect(Collectors.toList());
	}
}
