// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Example demonstrating the basic usage of templated URI in `fetch`
use templated_uri::{BaseUri, EscapedString, Uri, templated};

#[templated(template = "/{org_id}/user/{user_id}/{item}", unredacted)]
#[derive(Clone)]
struct UserPath {
    org_id: EscapedString,
    user_id: EscapedString,
    item: EscapedString,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let user_path = UserPath {
        org_id: EscapedString::from_static("Acme"),
        user_id: EscapedString::from_static("Will_E_Coyote"),
        item: EscapedString::from_static("name"),
    };
    let target = Uri::default()
        .with_base(BaseUri::from_static("https://example.com"))
        .with_path_and_query(user_path);

    let uri: http::Uri = target.try_into()?;

    println!("Constructed URI: {uri}");

    Ok(())
}
