package com.hdkj.lt.si.modle;

import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSONObject;
import com.hdkj.lt.core.rest.model.AbstractCallResponseEntity;
import com.hdkj.lt.modle.po.JoinEcTransformerPO;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

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

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

    private Integer count; //响应数量
    private String errors; //错误信息
    private String message; //响应信息
    private List<JoinEcTransformerPO> result; //响应数据
    private String status; //响应状态码

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

    @Override
    public Object getData() {
        List<JoinEcTransformerPO> joinEcTransformerList = result.stream()
                .map(entity -> {
                    JSONObject assetJson = entity.getAsset();
                    if (ObjectUtils.isNotEmpty(assetJson)) {
                        entity.setAstId(assetJson.getString("astId"));
                        entity.setAstNature(assetJson.getString("astNature"));
                        entity.setRatedCapacity(assetJson.getString("ratedCapacity"));
                    }
                    return entity;
                }).collect(Collectors.toList());
        return MapUtil.builder().put("resData", joinEcTransformerList).build();
    }

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