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


import com.xunhong.erp.turbo.api.infra.dto.cmd.MaterialBatchAddCmd;
import com.xunhong.erp.turbo.api.infra.dto.vo.MaterialVO;
import com.xunhong.erp.turbo.infra.app.assembler.MaterialAssembler;
import com.xunhong.erp.turbo.infra.domain.entity.Material;
import com.xunhong.erp.turbo.infra.domain.gateway.MaterialGateway;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class MaterialBatchAddCmdExe {

	private final MaterialGateway materialGateway;
	private final MaterialAssembler materialAssembler;

	public List<MaterialVO> execute(MaterialBatchAddCmd materialBatchAddCmd) {
		List<Material> materialList = materialGateway.save(materialBatchAddCmd);
		return materialList.stream().map(materialAssembler::toMaterialVO).toList();
	}
}
