// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.embed.getEmbedExternalView
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{AtUri, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::app_bsky::embed::external::View;
use crate::com_atproto::repo::strong_ref::StrongRef;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetEmbedExternalView<S: BosStr = DefaultStr> {
    pub uris: Vec<AtUri<S>>,
    pub url: UriValue<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetEmbedExternalViewOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub associated_records: Option<Vec<Data<S>>>,
    ///StrongRefs (URI+CID) of the Atmosphere records that backed this view, suitable for embedding into a post's external.associatedRefs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub associated_refs: Option<Vec<StrongRef<S>>>,
    ///Hydrated view of the embed. Present only when the resolved records back the requested URL and supply enough information to populate the required `viewExternal` fields. Omitted alongside the rest of the response when no records resolved or validation failed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub view: Option<View<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `app.bsky.embed.getEmbedExternalView` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetEmbedExternalViewOutput<S>` for this endpoint.*/
pub struct GetEmbedExternalViewResponse;
impl jacquard_common::xrpc::XrpcResp for GetEmbedExternalViewResponse {
    const NSID: &'static str = "app.bsky.embed.getEmbedExternalView";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetEmbedExternalViewOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetEmbedExternalView<S> {
    const NSID: &'static str = "app.bsky.embed.getEmbedExternalView";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetEmbedExternalViewResponse;
}

/** Endpoint marker for the `app.bsky.embed.getEmbedExternalView` query.

Path: `/xrpc/app.bsky.embed.getEmbedExternalView`. The request payload type is `GetEmbedExternalView<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetEmbedExternalViewRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetEmbedExternalViewRequest {
    const PATH: &'static str = "/xrpc/app.bsky.embed.getEmbedExternalView";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetEmbedExternalView<S>;
    type Response = GetEmbedExternalViewResponse;
}

pub mod get_embed_external_view_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Uris;
        type Url;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Uris = Unset;
        type Url = Unset;
    }
    ///State transition - sets the `uris` field to Set
    pub struct SetUris<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUris<St> {}
    impl<St: State> State for SetUris<St> {
        type Uris = Set<members::uris>;
        type Url = St::Url;
    }
    ///State transition - sets the `url` field to Set
    pub struct SetUrl<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUrl<St> {}
    impl<St: State> State for SetUrl<St> {
        type Uris = St::Uris;
        type Url = Set<members::url>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uris` field
        pub struct uris(());
        ///Marker type for the `url` field
        pub struct url(());
    }
}

/// Builder for constructing an instance of this type.
pub struct GetEmbedExternalViewBuilder<
    St: get_embed_external_view_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Vec<AtUri<S>>>, Option<UriValue<S>>),
    _type: PhantomData<fn() -> S>,
}

impl GetEmbedExternalView<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> GetEmbedExternalViewBuilder<
        get_embed_external_view_state::Empty,
        DefaultStr,
    > {
        GetEmbedExternalViewBuilder::new()
    }
}

impl<S: BosStr> GetEmbedExternalView<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetEmbedExternalViewBuilder<
        get_embed_external_view_state::Empty,
        S,
    > {
        GetEmbedExternalViewBuilder::builder()
    }
}

impl GetEmbedExternalViewBuilder<get_embed_external_view_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        GetEmbedExternalViewBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> GetEmbedExternalViewBuilder<get_embed_external_view_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        GetEmbedExternalViewBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetEmbedExternalViewBuilder<St, S>
where
    St: get_embed_external_view_state::State,
    St::Uris: get_embed_external_view_state::IsUnset,
{
    /// Set the `uris` field (required)
    pub fn uris(
        mut self,
        value: impl Into<Vec<AtUri<S>>>,
    ) -> GetEmbedExternalViewBuilder<get_embed_external_view_state::SetUris<St>, S> {
        self._fields.0 = Option::Some(value.into());
        GetEmbedExternalViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetEmbedExternalViewBuilder<St, S>
where
    St: get_embed_external_view_state::State,
    St::Url: get_embed_external_view_state::IsUnset,
{
    /// Set the `url` field (required)
    pub fn url(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> GetEmbedExternalViewBuilder<get_embed_external_view_state::SetUrl<St>, S> {
        self._fields.1 = Option::Some(value.into());
        GetEmbedExternalViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetEmbedExternalViewBuilder<St, S>
where
    St: get_embed_external_view_state::State,
    St::Uris: get_embed_external_view_state::IsSet,
    St::Url: get_embed_external_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetEmbedExternalView<S> {
        GetEmbedExternalView {
            uris: self._fields.0.unwrap(),
            url: self._fields.1.unwrap(),
        }
    }
}