// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.report.reassignQueue
//
// 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};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::tools_ozone::report::ReportView;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ReassignQueue<S: BosStr = DefaultStr> {
    ///Optional moderator-only note recorded on the resulting queueActivity as internalNote.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub comment: Option<S>,
    ///Target queue ID. Use -1 to unassign from any queue.
    pub queue_id: i64,
    ///ID of the report to reassign
    pub report_id: i64,
    #[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 ReassignQueueOutput<S: BosStr = DefaultStr> {
    pub report: ReportView<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,
    thiserror::Error,
    miette::Diagnostic
)]

#[serde(tag = "error", content = "message")]
pub enum ReassignQueueError {
    /// No report exists with the given reportId
    #[serde(rename = "ReportNotFound")]
    ReportNotFound(Option<SmolStr>),
    /// The report is closed and cannot be reassigned
    #[serde(rename = "ReportClosed")]
    ReportClosed(Option<SmolStr>),
    /// The report is already assigned to the target queue
    #[serde(rename = "AlreadyInTargetQueue")]
    AlreadyInTargetQueue(Option<SmolStr>),
    /// No active queue exists with the given queueId
    #[serde(rename = "QueueNotFound")]
    QueueNotFound(Option<SmolStr>),
    /// The target queue is disabled and cannot receive new assignments
    #[serde(rename = "QueueDisabled")]
    QueueDisabled(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for ReassignQueueError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::ReportNotFound(msg) => {
                write!(f, "ReportNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::ReportClosed(msg) => {
                write!(f, "ReportClosed")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::AlreadyInTargetQueue(msg) => {
                write!(f, "AlreadyInTargetQueue")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::QueueNotFound(msg) => {
                write!(f, "QueueNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::QueueDisabled(msg) => {
                write!(f, "QueueDisabled")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}

/** Response marker for the `tools.ozone.report.reassignQueue` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ReassignQueueOutput<S>` for this endpoint.*/
pub struct ReassignQueueResponse;
impl jacquard_common::xrpc::XrpcResp for ReassignQueueResponse {
    const NSID: &'static str = "tools.ozone.report.reassignQueue";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ReassignQueueOutput<S>;
    type Err = ReassignQueueError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ReassignQueue<S> {
    const NSID: &'static str = "tools.ozone.report.reassignQueue";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = ReassignQueueResponse;
}

/** Endpoint marker for the `tools.ozone.report.reassignQueue` procedure.

Path: `/xrpc/tools.ozone.report.reassignQueue`. The request payload type is `ReassignQueue<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ReassignQueueRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ReassignQueueRequest {
    const PATH: &'static str = "/xrpc/tools.ozone.report.reassignQueue";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = ReassignQueue<S>;
    type Response = ReassignQueueResponse;
}

pub mod reassign_queue_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 QueueId;
        type ReportId;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type QueueId = Unset;
        type ReportId = Unset;
    }
    ///State transition - sets the `queue_id` field to Set
    pub struct SetQueueId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetQueueId<St> {}
    impl<St: State> State for SetQueueId<St> {
        type QueueId = Set<members::queue_id>;
        type ReportId = St::ReportId;
    }
    ///State transition - sets the `report_id` field to Set
    pub struct SetReportId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReportId<St> {}
    impl<St: State> State for SetReportId<St> {
        type QueueId = St::QueueId;
        type ReportId = Set<members::report_id>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `queue_id` field
        pub struct queue_id(());
        ///Marker type for the `report_id` field
        pub struct report_id(());
    }
}

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

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

impl<S: BosStr> ReassignQueue<S> {
    /// Create a new builder for this type
    pub fn builder() -> ReassignQueueBuilder<reassign_queue_state::Empty, S> {
        ReassignQueueBuilder::builder()
    }
}

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

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

impl<St: reassign_queue_state::State, S: BosStr> ReassignQueueBuilder<St, S> {
    /// Set the `comment` field (optional)
    pub fn comment(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `comment` field to an Option value (optional)
    pub fn maybe_comment(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> ReassignQueueBuilder<St, S>
where
    St: reassign_queue_state::State,
    St::QueueId: reassign_queue_state::IsUnset,
{
    /// Set the `queueId` field (required)
    pub fn queue_id(
        mut self,
        value: impl Into<i64>,
    ) -> ReassignQueueBuilder<reassign_queue_state::SetQueueId<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ReassignQueueBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ReassignQueueBuilder<St, S>
where
    St: reassign_queue_state::State,
    St::ReportId: reassign_queue_state::IsUnset,
{
    /// Set the `reportId` field (required)
    pub fn report_id(
        mut self,
        value: impl Into<i64>,
    ) -> ReassignQueueBuilder<reassign_queue_state::SetReportId<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ReassignQueueBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ReassignQueueBuilder<St, S>
where
    St: reassign_queue_state::State,
    St::QueueId: reassign_queue_state::IsSet,
    St::ReportId: reassign_queue_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ReassignQueue<S> {
        ReassignQueue {
            comment: self._fields.0,
            queue_id: self._fields.1.unwrap(),
            report_id: 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<SmolStr, Data<S>>,
    ) -> ReassignQueue<S> {
        ReassignQueue {
            comment: self._fields.0,
            queue_id: self._fields.1.unwrap(),
            report_id: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}