/*
 * Copyright 2026 Snowflake Inc.
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <cstdint>
#include <optional>
#include <string>
#include <string_view>

namespace snowflake::ingest::streaming {

/// Read-only snapshot of a channel's status as reported by the Rust core.
///
/// Mirrors the CoreChannelStatus struct serialised over the C ABI.
struct channel_status {
  std::string database_name;
  std::string schema_name;
  std::string pipe_name;
  std::string channel_name;
  /// Raw status code string from Snowflake, e.g. "OK" or error codes.
  std::string status_code;
  std::optional<std::string> last_committed_offset_token;
  int64_t created_on_ms = 0;
  int64_t rows_inserted = 0;
  int64_t rows_parsed = 0;
  int64_t rows_error_count = 0;
  std::optional<std::string> last_error_offset_upper_bound;
  std::optional<std::string> last_error_message;
  std::optional<int64_t> last_error_timestamp_ms;
  std::optional<int64_t> snowflake_avg_processing_latency_ms;
  uint64_t last_refreshed_on_ms = 0;

  /// Parse a JSON-encoded CoreChannelStatus produced by the Rust core.
  static channel_status from_json(std::string_view json);

  /// Returns true if status_code indicates success ("OK" or "SUCCESS").
  bool is_status_ok() const noexcept {
    return status_code == "OK" || status_code == "SUCCESS";
  }
};

}  // namespace snowflake::ingest::streaming
