package com.usky.vpp.service.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * 需求响应策略创建/更新请求
 */
@Data
public class DrStrategyRequest {

    private String strategyCode;
    private String strategyName;
    private Integer responseType;
    private BigDecimal adjustStepKw;
    private Integer executeMode;
    @JsonProperty("strategyConfig")
    private JsonNode strategyConfigJson;
    private Integer isDefault;
    private Integer isEnabled;
    private List<DrStrategyResource> resources;

    /**
     * 策略扩展配置 JSON 字符串（兼容对象或字符串入参）
     */
    @JsonIgnore
    public String getStrategyConfig() {
        if (strategyConfigJson == null || strategyConfigJson.isNull()) {
            return null;
        }
        if (strategyConfigJson.isTextual()) {
            return strategyConfigJson.asText();
        }
        return strategyConfigJson.toString();
    }

    @Data
    public static class DrStrategyResource {
        private Long resourceId;
        private Integer priority;
        private BigDecimal maxAdjustKw;
    }
}