// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.git.temp.analyzeMerge
//
// 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::{CowStr, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::Did;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::sh_tangled::git::temp::analyze_merge;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ConflictInfo<S: BosStr = DefaultStr> {
    ///Name of the conflicted file
    pub filename: S,
    ///Reason for the conflict
    pub reason: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct AnalyzeMerge<S: BosStr = DefaultStr> {
    pub branch: S,
    pub patch: S,
    pub repo: Did<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct AnalyzeMergeOutput<S: BosStr = DefaultStr> {
    ///List of files with merge conflicts
    #[serde(skip_serializing_if = "Option::is_none")]
    pub conflicts: Option<Vec<analyze_merge::ConflictInfo<S>>>,
    ///Whether the merge has conflicts
    pub is_conflicted: bool,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for ConflictInfo<S> {
    fn nsid() -> &'static str {
        "sh.tangled.git.temp.analyzeMerge"
    }
    fn def_name() -> &'static str {
        "conflictInfo"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_temp_analyzeMerge()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `sh.tangled.git.temp.analyzeMerge` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `AnalyzeMergeOutput<S>` for this endpoint.*/
pub struct AnalyzeMergeResponse;
impl jacquard_common::xrpc::XrpcResp for AnalyzeMergeResponse {
    const NSID: &'static str = "sh.tangled.git.temp.analyzeMerge";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = AnalyzeMergeOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for AnalyzeMerge<S> {
    const NSID: &'static str = "sh.tangled.git.temp.analyzeMerge";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = AnalyzeMergeResponse;
}

/** Endpoint marker for the `sh.tangled.git.temp.analyzeMerge` query.

Path: `/xrpc/sh.tangled.git.temp.analyzeMerge`. The request payload type is `AnalyzeMerge<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct AnalyzeMergeRequest;
impl jacquard_common::xrpc::XrpcEndpoint for AnalyzeMergeRequest {
    const PATH: &'static str = "/xrpc/sh.tangled.git.temp.analyzeMerge";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = AnalyzeMerge<S>;
    type Response = AnalyzeMergeResponse;
}

fn lexicon_doc_sh_tangled_git_temp_analyzeMerge() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("sh.tangled.git.temp.analyzeMerge"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("conflictInfo"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("filename"),
                            SmolStr::new_static("reason")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("filename"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Name of the conflicted file"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("reason"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Reason for the conflict"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(
                                vec![
                                    SmolStr::new_static("repo"), SmolStr::new_static("patch"),
                                    SmolStr::new_static("branch")
                                ],
                            ),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("branch"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("Target branch to merge into"),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("patch"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "Patch or pull request to check for merge conflicts",
                                            ),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("repo"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("DID of the repository"),
                                        ),
                                        format: Some(LexStringFormat::Did),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod analyze_merge_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 Branch;
        type Patch;
        type Repo;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Branch = Unset;
        type Patch = Unset;
        type Repo = Unset;
    }
    ///State transition - sets the `branch` field to Set
    pub struct SetBranch<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetBranch<St> {}
    impl<St: State> State for SetBranch<St> {
        type Branch = Set<members::branch>;
        type Patch = St::Patch;
        type Repo = St::Repo;
    }
    ///State transition - sets the `patch` field to Set
    pub struct SetPatch<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPatch<St> {}
    impl<St: State> State for SetPatch<St> {
        type Branch = St::Branch;
        type Patch = Set<members::patch>;
        type Repo = St::Repo;
    }
    ///State transition - sets the `repo` field to Set
    pub struct SetRepo<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRepo<St> {}
    impl<St: State> State for SetRepo<St> {
        type Branch = St::Branch;
        type Patch = St::Patch;
        type Repo = Set<members::repo>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `branch` field
        pub struct branch(());
        ///Marker type for the `patch` field
        pub struct patch(());
        ///Marker type for the `repo` field
        pub struct repo(());
    }
}

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

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

impl<S: BosStr> AnalyzeMerge<S> {
    /// Create a new builder for this type
    pub fn builder() -> AnalyzeMergeBuilder<analyze_merge_state::Empty, S> {
        AnalyzeMergeBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> AnalyzeMergeBuilder<St, S>
where
    St: analyze_merge_state::State,
    St::Branch: analyze_merge_state::IsUnset,
{
    /// Set the `branch` field (required)
    pub fn branch(
        mut self,
        value: impl Into<S>,
    ) -> AnalyzeMergeBuilder<analyze_merge_state::SetBranch<St>, S> {
        self._fields.0 = Option::Some(value.into());
        AnalyzeMergeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> AnalyzeMergeBuilder<St, S>
where
    St: analyze_merge_state::State,
    St::Patch: analyze_merge_state::IsUnset,
{
    /// Set the `patch` field (required)
    pub fn patch(
        mut self,
        value: impl Into<S>,
    ) -> AnalyzeMergeBuilder<analyze_merge_state::SetPatch<St>, S> {
        self._fields.1 = Option::Some(value.into());
        AnalyzeMergeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> AnalyzeMergeBuilder<St, S>
where
    St: analyze_merge_state::State,
    St::Repo: analyze_merge_state::IsUnset,
{
    /// Set the `repo` field (required)
    pub fn repo(
        mut self,
        value: impl Into<Did<S>>,
    ) -> AnalyzeMergeBuilder<analyze_merge_state::SetRepo<St>, S> {
        self._fields.2 = Option::Some(value.into());
        AnalyzeMergeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> AnalyzeMergeBuilder<St, S>
where
    St: analyze_merge_state::State,
    St::Branch: analyze_merge_state::IsSet,
    St::Patch: analyze_merge_state::IsSet,
    St::Repo: analyze_merge_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> AnalyzeMerge<S> {
        AnalyzeMerge {
            branch: self._fields.0.unwrap(),
            patch: self._fields.1.unwrap(),
            repo: self._fields.2.unwrap(),
        }
    }
}