// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use serde::{Deserialize, Serialize};

/// Request parameters for the `getOracles` RPC method
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetOraclesRequest {
    /// Oracle creator pubkey, that is pubkey of the account that created the oracle request.
    pub creator: String,

    /// Hex representation of the nonce associated with a specific oracle.
    /// If empty, it will retrieve the most recently created oracles of the given creator.
    /// The result is truncated to an amount of oracle that `OracleRegistry` holds in memory.
    pub nonce: Option<String>,
}

/// The response message for a getOracles request.
#[derive(Serialize, Deserialize, Debug)]
pub struct GetOraclesResponse {
    pub oracles: Vec<OracleInfoAndDuties>,
}

/// Oracle information combined with its associated duties
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct OracleInfoAndDuties {
    /// Pubkey of an account that created the oracle.
    pub creator: String,
    /// Hex representation of the oracle's nonce.
    pub nonce: String,

    /// See OracleInfo for documentation.
    pub is_active: bool,
    pub description: String,
    pub update_frequency: String,
    pub starting_round: String,
    pub created_at: i64,
    pub aggregator_topics: Vec<String>,
    pub aggregator_pubkeys: Vec<String>,
    pub validators_per_duty: u32,
    pub num_retries: u32,
    pub retry_delay: u32,
    pub oracle_request_delay: u32,
    pub compute_units_limit: Option<u32>,
    pub heap_size_limit: Option<u32>,

    /// A list of all matching oracle duties that currently expect oracle updates or got their oracle updates and expect commitment.
    /// Usually this happens 9 rounds before the duty gets committed.
    /// More precisely, `oracle_request_delay` + 3 rounds before the duty gets committed.
    pub duties: Vec<OracleDuty>,
}

/// Represents a single oracle duty assignment for a specific proposal round
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct OracleDuty {
    /// Target proposal round of this oracle duty.
    pub proposal_round: u64,

    /// Hex representation of validators' ProtocolPublicKeys.
    pub assigned_validators: Vec<String>,
}
