package com.dexorder.flink.ingestor;

import java.util.ArrayList;
import java.util.List;

/**
 * Represents a DataResponse message from an ingestor.
 * Contains the results of a historical data request.
 */
public class DataResponseMessage {
    private final String requestId;
    private final ResponseStatus status;
    private final String errorMessage;
    private final List<byte[]> ohlcData;
    private final int totalRecords;

    public enum ResponseStatus {
        OK,
        NOT_FOUND,
        ERROR
    }

    public DataResponseMessage(String requestId, ResponseStatus status, String errorMessage,
                              List<byte[]> ohlcData, int totalRecords) {
        this.requestId = requestId;
        this.status = status;
        this.errorMessage = errorMessage;
        this.ohlcData = ohlcData != null ? ohlcData : new ArrayList<>();
        this.totalRecords = totalRecords;
    }

    public String getRequestId() {
        return requestId;
    }

    public ResponseStatus getStatus() {
        return status;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public List<byte[]> getOhlcData() {
        return ohlcData;
    }

    public int getTotalRecords() {
        return totalRecords;
    }

    /**
     * Deserialize from protobuf bytes.
     * TODO: Replace with actual generated protobuf deserialization
     */
    public static DataResponseMessage fromProtobuf(byte[] protobufData) {
        // Placeholder - will be replaced with actual protobuf deserialization
        // For now, return a dummy response
        return new DataResponseMessage("", ResponseStatus.ERROR, "Not implemented", null, 0);
    }

    /**
     * Serialize to protobuf bytes.
     * TODO: Replace with actual generated protobuf serialization
     */
    public byte[] toProtobuf() {
        // Placeholder - will be replaced with actual protobuf serialization
        return new byte[0];
    }

    /**
     * Create a successful response.
     */
    public static DataResponseMessage success(String requestId, List<byte[]> ohlcData) {
        return new DataResponseMessage(requestId, ResponseStatus.OK, null, ohlcData, ohlcData.size());
    }

    /**
     * Create an error response.
     */
    public static DataResponseMessage error(String requestId, String errorMessage) {
        return new DataResponseMessage(requestId, ResponseStatus.ERROR, errorMessage, null, 0);
    }

    /**
     * Create a not found response.
     */
    public static DataResponseMessage notFound(String requestId) {
        return new DataResponseMessage(requestId, ResponseStatus.NOT_FOUND, "Data not found", null, 0);
    }
}
