# frozen_string_literal: true

module SynorDatabase
  # Configuration for the database client
  Config = Struct.new(:api_key, :base_url, :timeout, :retries, :debug, keyword_init: true) do
    def initialize(api_key:, base_url: "https://db.synor.io/v1", timeout: 60, retries: 3, debug: false)
      super(api_key: api_key, base_url: base_url, timeout: timeout, retries: retries, debug: debug)
    end
  end

  # A key-value entry
  KeyValue = Struct.new(:key, :value, :ttl, :created_at, :updated_at, keyword_init: true) do
    def self.from_hash(hash)
      new(
        key: hash["key"],
        value: hash["value"],
        ttl: hash["ttl"],
        created_at: hash["created_at"],
        updated_at: hash["updated_at"]
      )
    end
  end

  # A document
  Document = Struct.new(:id, :collection, :data, :created_at, :updated_at, keyword_init: true) do
    def self.from_hash(hash)
      new(
        id: hash["id"],
        collection: hash["collection"],
        data: hash["data"],
        created_at: hash["created_at"],
        updated_at: hash["updated_at"]
      )
    end
  end

  # Query parameters for documents
  Query = Struct.new(:filter, :sort, :limit, :offset, :projection, keyword_init: true)

  # A vector entry
  VectorEntry = Struct.new(:id, :vector, :metadata, keyword_init: true)

  # A search result
  SearchResult = Struct.new(:id, :score, :vector, :metadata, keyword_init: true) do
    def self.from_hash(hash)
      new(
        id: hash["id"],
        score: hash["score"],
        vector: hash["vector"],
        metadata: hash["metadata"]
      )
    end
  end

  # A time series data point
  DataPoint = Struct.new(:timestamp, :value, :tags, keyword_init: true) do
    def self.from_hash(hash)
      new(
        timestamp: hash["timestamp"],
        value: hash["value"],
        tags: hash["tags"]
      )
    end
  end

  # Time range for queries
  TimeRange = Struct.new(:start, :end, keyword_init: true)

  # Aggregation settings
  Aggregation = Struct.new(:function, :interval, keyword_init: true)
end
