//! `mijia-spec` is a compact Rust library for Xiaomi MIoT device specs.
//!
//! ## Introduction
//!
//! The crate fetches official MIoT v2 instance/translation payloads by device URN
//! and builds a query-oriented `DeviceSpec` model for downstream tooling.
//!
//! ## API Interfaces
//!
//! - `miot_spec_v2::fetch_spec(urn)` (`sync`): fetch MIoT v2 instance in synchronous mode.
//! - `miot_spec_v2::fetch_spec_async(urn)` (`async`): fetch MIoT v2 instance in asynchronous mode.
//! - `MijiaSpecClient`: optional memory/disk cache wrapper around fetch APIs.
//!
//! ## Feature Options
//!
//! - `sync`: synchronous fetch APIs.
//! - `async`: asynchronous fetch APIs.
//! - `ureq-client`: sync HTTP backend via `ureq`.
//! - `reqwest-client`: HTTP backend via `reqwest` (blocking/async).
//! - `cli`: binary entry (`mijia-spec`) using clap.
//!
//! ## CLI
//!
//! ```bash
//! cargo run --features cli -- --urn urn:miot-spec-v2:device:light:0000A001:yeelink-mbulb3:1:0000C802 --pretty
//! ```

/// HTTP User-Agent sent by built-in clients.
pub const USER_AGENT: &str = concat!("mijia-spec-rs/", env!("CARGO_PKG_VERSION"));

/// Errors returned by parsing, fetching, and cache operations.
#[derive(Debug, thiserror::Error)]
pub enum SpecError {
    #[error("HTTP request failed: {0}")]
    Http(String),
    #[error("HTTP status error: {0}")]
    HttpStatus(u16),
    #[error("Missing data-page attribute in HTML")]
    MissingData,
    #[error("JSON processing failed: {0}")]
    Json(#[from] serde_json::Error),
    #[error("Unsupported property format: {0}")]
    UnsupportedFormat(String),
    #[error("Feature not enabled: {0}")]
    Feature(&'static str),
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),
}

mod cache;
pub mod client;
pub mod miot_spec_v2;

#[cfg(feature = "sync")]
pub use miot_spec_v2::{fetch_spec, fetch_translation};
#[cfg(feature = "async")]
pub use miot_spec_v2::{fetch_spec_async, fetch_translation_async};

pub use client::SpecClient as MijiaSpecClient;
pub use miot_spec_v2::query::DeviceSpec;
