package com.hdkj.lt.si.modle;

import com.hdkj.lt.core.rest.model.AbstractCallResponseEntity;
import com.hdkj.lt.modle.vo.psrdevice.PsrDeviceResponseVO;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @Description
 * @Author wcx
 * @Date 2025/7/30 9:14
 * @Version 1.0
 */
@Getter
@Setter
public class PsrDeviceCommonResponseEntity extends AbstractCallResponseEntity {

    private String errors; //错误信息
    private String message; //响应信息
    private Map<String, PsrDeviceResponseVO> result; //响应数据
    private String status; //响应状态码

    @Override
    public Object getCode() {
        return status;
    }

    @Override
    public Object getData() {
        // 接口返回设备信息
        AtomicReference<PsrDeviceResponseVO> device = new AtomicReference<>();
        result.forEach((key, value) -> Optional.ofNullable(value)
                .filter(e -> ObjectUtils.isEmpty(device.get()))
                .ifPresent(entity -> device.set(entity)));
        return device.get();
    }

    @Override
    public String getMsg() {
        return Optional.ofNullable(errors).filter(StringUtils::isNotEmpty).orElse(message);
    }
}
