package com.aegis.resource.equipment.assembler;

import com.aegis.resource.equipment.domain.Equipment;
import com.aegis.resource.equipment.domain.EquipmentCapability;
import com.aegis.resource.equipment.dto.EquipmentDTO;

/**
 * 装备对象转换器（Assembler）
 * 负责 DTO 和领域对象之间的转换（基础设施层职责）
 * 
 * @author aegis
 */
public class EquipmentAssembler {
    
    /**
     * 将 DTO 转换为领域对象
     */
    public static Equipment toDomain(EquipmentDTO dto) {
        Equipment equipment = new Equipment();
        equipment.setId(dto.getId());
        equipment.setEquipmentCode(dto.getEquipmentCode());
        equipment.setEquipmentName(dto.getEquipmentName());
        equipment.setEquipmentType(dto.getEquipmentType());
        equipment.setBrand(dto.getBrand());
        equipment.setModel(dto.getModel());
        equipment.setTeamId(dto.getTeamId());
        equipment.setWarehouseId(dto.getWarehouseId());
        equipment.setStatus(dto.getStatus());
        equipment.setPurchaseDate(dto.getPurchaseDate());
        equipment.setWarrantyDate(dto.getWarrantyDate());
        equipment.setRemark(dto.getRemark());
        
        // 将 DTO 的 List 转换为值对象，再转换为存储格式
        try {
            if (dto.getCapabilities() != null) {
                EquipmentCapability capability = EquipmentCapability.of(dto.getCapabilities());
                equipment.setCapabilities(capability.toStorageFormat());
            }
        } catch (Exception e) {
            // 转换失败时保持原样，让后续验证处理
        }
        
        return equipment;
    }
}

