package com.smyhub.infogenie.infogeniebackendjava.dto.response;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Generic response wrapper for all vertical AI-tool endpoints.
 * The "payload" map is serialised as flat top-level JSON fields via @JsonAnyGetter,
 * allowing each tool to return its own named fields alongside "success" and "timestamp".
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AIToolResponse {

    private boolean success = true;
    private long timestamp;
    private String error;

    private final Map<String, Object> payload = new LinkedHashMap<>();

    public boolean isSuccess() { return success; }
    public void setSuccess(boolean success) { this.success = success; }

    public long getTimestamp() { return timestamp; }
    public void setTimestamp(long timestamp) { this.timestamp = timestamp; }

    public String getError() { return error; }
    public void setError(String error) { this.error = error; }

    public AIToolResponse addField(String key, Object value) {
        payload.put(key, value);
        return this;
    }

    @JsonAnyGetter
    public Map<String, Object> getExtraFields() {
        return payload;
    }
}
