// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.pipeline.cancelPipeline
//
// 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::AtUri;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CancelPipeline<'a> {
    ///pipeline at-uri
    #[serde(borrow)]
    pub pipeline: AtUri<'a>,
    ///repo at-uri, spindle can't resolve repo from pipeline at-uri yet
    #[serde(borrow)]
    pub repo: AtUri<'a>,
    ///workflow name
    #[serde(borrow)]
    pub workflow: CowStr<'a>,
}

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

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

/// Endpoint type for sh.tangled.pipeline.cancelPipeline
pub struct CancelPipelineRequest;
impl jacquard_common::xrpc::XrpcEndpoint for CancelPipelineRequest {
    const PATH: &'static str = "/xrpc/sh.tangled.pipeline.cancelPipeline";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = CancelPipeline<'de>;
    type Response = CancelPipelineResponse;
}

pub mod cancel_pipeline_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 Repo;
        type Workflow;
        type Pipeline;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Repo = Unset;
        type Workflow = Unset;
        type Pipeline = Unset;
    }
    ///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 Repo = Set<members::repo>;
        type Workflow = S::Workflow;
        type Pipeline = S::Pipeline;
    }
    ///State transition - sets the `workflow` field to Set
    pub struct SetWorkflow<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetWorkflow<S> {}
    impl<S: State> State for SetWorkflow<S> {
        type Repo = S::Repo;
        type Workflow = Set<members::workflow>;
        type Pipeline = S::Pipeline;
    }
    ///State transition - sets the `pipeline` field to Set
    pub struct SetPipeline<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPipeline<S> {}
    impl<S: State> State for SetPipeline<S> {
        type Repo = S::Repo;
        type Workflow = S::Workflow;
        type Pipeline = Set<members::pipeline>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `repo` field
        pub struct repo(());
        ///Marker type for the `workflow` field
        pub struct workflow(());
        ///Marker type for the `pipeline` field
        pub struct pipeline(());
    }
}

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

impl<'a> CancelPipeline<'a> {
    /// Create a new builder for this type
    pub fn new() -> CancelPipelineBuilder<'a, cancel_pipeline_state::Empty> {
        CancelPipelineBuilder::new()
    }
}

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

impl<'a, S> CancelPipelineBuilder<'a, S>
where
    S: cancel_pipeline_state::State,
    S::Pipeline: cancel_pipeline_state::IsUnset,
{
    /// Set the `pipeline` field (required)
    pub fn pipeline(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> CancelPipelineBuilder<'a, cancel_pipeline_state::SetPipeline<S>> {
        self._fields.0 = Option::Some(value.into());
        CancelPipelineBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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

impl<'a, S> CancelPipelineBuilder<'a, S>
where
    S: cancel_pipeline_state::State,
    S::Repo: cancel_pipeline_state::IsSet,
    S::Workflow: cancel_pipeline_state::IsSet,
    S::Pipeline: cancel_pipeline_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CancelPipeline<'a> {
        CancelPipeline {
            pipeline: self._fields.0.unwrap(),
            repo: self._fields.1.unwrap(),
            workflow: self._fields.2.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>,
        >,
    ) -> CancelPipeline<'a> {
        CancelPipeline {
            pipeline: self._fields.0.unwrap(),
            repo: self._fields.1.unwrap(),
            workflow: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}