use std::time::Duration;

use anyhow::Error;
use async_trait::async_trait;

/// Trait for Election client operations
#[async_trait]
pub trait ElectionClient: Send + Sync {
    // Try to campaign as leader.
    // 1. If already be leader, lease keep alive, block until not be leader.
    // 2. If not leader, try to be the leader, block until be the leader.
    // Return leader lease id if it is leader.
    async fn campaign(&self, lease_timeout: Duration) -> Result<Option<i64>, Error>;

    // Is leader or not.
    async fn is_leader(&self) -> Result<bool, Error>;

    // Releases election leadership.
    async fn resign(&self) -> Result<(), Error>;
}
