package com.ruoyi.ss.device.service.impl;

import com.ruoyi.ss.device.domain.DeviceBO;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceConverter;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.device.service.DeviceValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wjh
 * 2024/7/15
 */
@Service
public class DeviceConverterImpl implements DeviceConverter {

    @Autowired
    private DeviceService deviceService;

    @Autowired
    private DeviceValidator deviceValidator;


    @Override
    public DeviceBO toBOByAppUpdate(DeviceBO data, Long userId) {
        if (data == null) {
            return null;
        }

        DeviceBO bo = new DeviceBO();
        bo.setDeviceId(data.getDeviceId());
        bo.setRemark(data.getRemark());
        bo.setDeviceName(data.getDeviceName());
        bo.setCustomPicture(data.getCustomPicture());

        // 仅允许商户修改的字段
        if (deviceValidator.isMch(data.getDeviceId(), userId)) {
            bo.setSuitIds(data.getSuitIds());
            bo.setStoreId(data.getStoreId());
        }
        return bo;
    }
}
