// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.repo.merge
//
// 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;
use jacquard_common::types::string::Did;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Merge<'a> {
    ///Author email for the merge commit
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub author_email: Option<CowStr<'a>>,
    ///Author name for the merge commit
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub author_name: Option<CowStr<'a>>,
    ///Target branch to merge into
    #[serde(borrow)]
    pub branch: CowStr<'a>,
    ///Additional commit message body
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub commit_body: Option<CowStr<'a>>,
    ///Merge commit message
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub commit_message: Option<CowStr<'a>>,
    ///DID of the repository owner
    #[serde(borrow)]
    pub did: Did<'a>,
    ///Name of the repository
    #[serde(borrow)]
    pub name: CowStr<'a>,
    ///Patch content to merge
    #[serde(borrow)]
    pub patch: CowStr<'a>,
}

/// Response type for sh.tangled.repo.merge
pub struct MergeResponse;
impl jacquard_common::xrpc::XrpcResp for MergeResponse {
    const NSID: &'static str = "sh.tangled.repo.merge";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = ();
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for Merge<'a> {
    const NSID: &'static str = "sh.tangled.repo.merge";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = MergeResponse;
}

/// Endpoint type for sh.tangled.repo.merge
pub struct MergeRequest;
impl jacquard_common::xrpc::XrpcEndpoint for MergeRequest {
    const PATH: &'static str = "/xrpc/sh.tangled.repo.merge";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = Merge<'de>;
    type Response = MergeResponse;
}

pub mod 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 Did;
        type Patch;
        type Branch;
        type Name;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Did = Unset;
        type Patch = Unset;
        type Branch = Unset;
        type Name = Unset;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDid<S> {}
    impl<S: State> State for SetDid<S> {
        type Did = Set<members::did>;
        type Patch = S::Patch;
        type Branch = S::Branch;
        type Name = S::Name;
    }
    ///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 Did = S::Did;
        type Patch = Set<members::patch>;
        type Branch = S::Branch;
        type Name = S::Name;
    }
    ///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 Did = S::Did;
        type Patch = S::Patch;
        type Branch = Set<members::branch>;
        type Name = S::Name;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type Did = S::Did;
        type Patch = S::Patch;
        type Branch = S::Branch;
        type Name = Set<members::name>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `patch` field
        pub struct patch(());
        ///Marker type for the `branch` field
        pub struct branch(());
        ///Marker type for the `name` field
        pub struct name(());
    }
}

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

impl<'a> Merge<'a> {
    /// Create a new builder for this type
    pub fn new() -> MergeBuilder<'a, merge_state::Empty> {
        MergeBuilder::new()
    }
}

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

impl<'a, S: merge_state::State> MergeBuilder<'a, S> {
    /// Set the `authorEmail` field (optional)
    pub fn author_email(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `authorEmail` field to an Option value (optional)
    pub fn maybe_author_email(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: merge_state::State> MergeBuilder<'a, S> {
    /// Set the `authorName` field (optional)
    pub fn author_name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `authorName` field to an Option value (optional)
    pub fn maybe_author_name(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<'a, S: merge_state::State> MergeBuilder<'a, S> {
    /// Set the `commitBody` field (optional)
    pub fn commit_body(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `commitBody` field to an Option value (optional)
    pub fn maybe_commit_body(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S: merge_state::State> MergeBuilder<'a, S> {
    /// Set the `commitMessage` field (optional)
    pub fn commit_message(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `commitMessage` field to an Option value (optional)
    pub fn maybe_commit_message(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S> MergeBuilder<'a, S>
where
    S: merge_state::State,
    S::Did: merge_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> MergeBuilder<'a, merge_state::SetDid<S>> {
        self._fields.5 = Option::Some(value.into());
        MergeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MergeBuilder<'a, S>
where
    S: merge_state::State,
    S::Name: merge_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> MergeBuilder<'a, merge_state::SetName<S>> {
        self._fields.6 = Option::Some(value.into());
        MergeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> MergeBuilder<'a, S>
where
    S: merge_state::State,
    S::Did: merge_state::IsSet,
    S::Patch: merge_state::IsSet,
    S::Branch: merge_state::IsSet,
    S::Name: merge_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Merge<'a> {
        Merge {
            author_email: self._fields.0,
            author_name: self._fields.1,
            branch: self._fields.2.unwrap(),
            commit_body: self._fields.3,
            commit_message: self._fields.4,
            did: self._fields.5.unwrap(),
            name: self._fields.6.unwrap(),
            patch: self._fields.7.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Merge<'a> {
        Merge {
            author_email: self._fields.0,
            author_name: self._fields.1,
            branch: self._fields.2.unwrap(),
            commit_body: self._fields.3,
            commit_message: self._fields.4,
            did: self._fields.5.unwrap(),
            name: self._fields.6.unwrap(),
            patch: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}