// @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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::AtUri;
use jacquard_derive::{IntoStatic, lexicon};
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;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ConflictInfo<'a> {
    ///Name of the conflicted file
    #[serde(borrow)]
    pub filename: CowStr<'a>,
    ///Reason for the conflict
    #[serde(borrow)]
    pub reason: CowStr<'a>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct AnalyzeMerge<'a> {
    #[serde(borrow)]
    pub branch: CowStr<'a>,
    #[serde(borrow)]
    pub patch: CowStr<'a>,
    #[serde(borrow)]
    pub repo: AtUri<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct AnalyzeMergeOutput<'a> {
    ///List of files with merge conflicts
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub conflicts: Option<Vec<analyze_merge::ConflictInfo<'a>>>,
    ///Whether the merge has conflicts
    pub is_conflicted: bool,
}

impl<'a> LexiconSchema for ConflictInfo<'a> {
    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 type for sh.tangled.git.temp.analyzeMerge
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<'de> = AnalyzeMergeOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Endpoint type for sh.tangled.git.temp.analyzeMerge
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<'de> = AnalyzeMerge<'de>;
    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("AT-URI of the repository"),
                                        ),
                                        format: Some(LexStringFormat::AtUri),
                                        ..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 Repo;
        type Patch;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Branch = Unset;
        type Repo = Unset;
        type Patch = Unset;
    }
    ///State transition - sets the `branch` field to Set
    pub struct SetBranch<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetBranch<S> {}
    impl<S: State> State for SetBranch<S> {
        type Branch = Set<members::branch>;
        type Repo = S::Repo;
        type Patch = S::Patch;
    }
    ///State transition - sets the `repo` field to Set
    pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRepo<S> {}
    impl<S: State> State for SetRepo<S> {
        type Branch = S::Branch;
        type Repo = Set<members::repo>;
        type Patch = S::Patch;
    }
    ///State transition - sets the `patch` field to Set
    pub struct SetPatch<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPatch<S> {}
    impl<S: State> State for SetPatch<S> {
        type Branch = S::Branch;
        type Repo = S::Repo;
        type Patch = Set<members::patch>;
    }
    /// 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 `repo` field
        pub struct repo(());
        ///Marker type for the `patch` field
        pub struct patch(());
    }
}

/// Builder for constructing an instance of this type
pub struct AnalyzeMergeBuilder<'a, S: analyze_merge_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<AtUri<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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