//! Shared appview handler state.
//!
//! PM-26 read endpoints are backed entirely by the SQLite projection (records
//! live in `record_json`, handles in `identities`, profiles in `profiles`). The
//! read path therefore needs no Hydrant handle. `resolver` canonicalizes handle
//! authorities to DIDs for `getProfile`; `bsky` fetches the
//! `app.bsky.actor.defs#profileViewDetailed` union variant from the public
//! AppView for actors with no polymodel profile.

use jacquard::client::BasicClient;
use jacquard::identity::PublicResolver;
use sqlx::SqlitePool;

/// State shared by all XRPC read handlers.
pub struct AppState {
    /// SQLite projection (PM-25): content, social counts, profiles, identities.
    pub pool: SqlitePool,
    /// Handle→DID resolution for `getProfile` actor canonicalization.
    pub resolver: PublicResolver,
    /// Unauthenticated client aimed at the public Bluesky AppView
    /// (`https://public.api.bsky.app`) for the bluesky-only profile variant.
    pub bsky: BasicClient,
}

impl AppState {
    /// Construct read state from the shared SQLite pool. The resolver and bsky
    /// client are unauthenticated/public and need no configuration.
    pub fn new(pool: SqlitePool) -> Self {
        Self {
            pool,
            resolver: jacquard::identity::slingshot_resolver_default(),
            bsky: jacquard::client::BasicClient::unauthenticated(),
        }
    }
}
