// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.moderation.createReport
//
// 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, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
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::com_atproto::admin::RepoRef;
use crate::com_atproto::moderation::ReasonType;
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::com_atproto::moderation::create_report;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CreateReport<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mod_tool: Option<create_report::ModTool<S>>,
    ///Additional context about the content and violation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<S>,
    ///Indicates the broad category of violation the report is for.
    pub reason_type: ReasonType<S>,
    pub subject: CreateReportSubject<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CreateReportSubject<S: BosStr = DefaultStr> {
    #[serde(rename = "com.atproto.admin.defs#repoRef")]
    RepoRef(Box<RepoRef<S>>),
    #[serde(rename = "com.atproto.repo.strongRef")]
    StrongRef(Box<StrongRef<S>>),
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CreateReportOutput<S: BosStr = DefaultStr> {
    pub created_at: Datetime,
    pub id: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<S>,
    pub reason_type: ReasonType<S>,
    pub reported_by: Did<S>,
    pub subject: CreateReportOutputSubject<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CreateReportOutputSubject<S: BosStr = DefaultStr> {
    #[serde(rename = "com.atproto.admin.defs#repoRef")]
    RepoRef(Box<RepoRef<S>>),
    #[serde(rename = "com.atproto.repo.strongRef")]
    StrongRef(Box<StrongRef<S>>),
}

/// Moderation tool information for tracing the source of the action

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ModTool<S: BosStr = DefaultStr> {
    ///Additional arbitrary metadata about the source
    #[serde(skip_serializing_if = "Option::is_none")]
    pub meta: Option<Data<S>>,
    ///Name/identifier of the source (e.g., 'bsky-app/android', 'bsky-web/chrome')
    pub name: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `com.atproto.moderation.createReport` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `CreateReportOutput<S>` for this endpoint.*/
pub struct CreateReportResponse;
impl jacquard_common::xrpc::XrpcResp for CreateReportResponse {
    const NSID: &'static str = "com.atproto.moderation.createReport";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = CreateReportOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateReport<S> {
    const NSID: &'static str = "com.atproto.moderation.createReport";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = CreateReportResponse;
}

/** Endpoint marker for the `com.atproto.moderation.createReport` procedure.

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

impl<S: BosStr> LexiconSchema for ModTool<S> {
    fn nsid() -> &'static str {
        "com.atproto.moderation.createReport"
    }
    fn def_name() -> &'static str {
        "modTool"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_moderation_createReport()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod create_report_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 ReasonType;
        type Subject;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type ReasonType = Unset;
        type Subject = Unset;
    }
    ///State transition - sets the `reason_type` field to Set
    pub struct SetReasonType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReasonType<St> {}
    impl<St: State> State for SetReasonType<St> {
        type ReasonType = Set<members::reason_type>;
        type Subject = St::Subject;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSubject<St> {}
    impl<St: State> State for SetSubject<St> {
        type ReasonType = St::ReasonType;
        type Subject = Set<members::subject>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `reason_type` field
        pub struct reason_type(());
        ///Marker type for the `subject` field
        pub struct subject(());
    }
}

/// Builder for constructing an instance of this type.
pub struct CreateReportBuilder<St: create_report_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<create_report::ModTool<S>>,
        Option<S>,
        Option<ReasonType<S>>,
        Option<CreateReportSubject<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> CreateReport<S> {
    /// Create a new builder for this type
    pub fn builder() -> CreateReportBuilder<create_report_state::Empty, S> {
        CreateReportBuilder::builder()
    }
}

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

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

impl<St: create_report_state::State, S: BosStr> CreateReportBuilder<St, S> {
    /// Set the `modTool` field (optional)
    pub fn mod_tool(
        mut self,
        value: impl Into<Option<create_report::ModTool<S>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `modTool` field to an Option value (optional)
    pub fn maybe_mod_tool(mut self, value: Option<create_report::ModTool<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: create_report_state::State, S: BosStr> CreateReportBuilder<St, S> {
    /// Set the `reason` field (optional)
    pub fn reason(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `reason` field to an Option value (optional)
    pub fn maybe_reason(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> CreateReportBuilder<St, S>
where
    St: create_report_state::State,
    St::ReasonType: create_report_state::IsUnset,
{
    /// Set the `reasonType` field (required)
    pub fn reason_type(
        mut self,
        value: impl Into<ReasonType<S>>,
    ) -> CreateReportBuilder<create_report_state::SetReasonType<St>, S> {
        self._fields.2 = Option::Some(value.into());
        CreateReportBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CreateReportBuilder<St, S>
where
    St: create_report_state::State,
    St::Subject: create_report_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<CreateReportSubject<S>>,
    ) -> CreateReportBuilder<create_report_state::SetSubject<St>, S> {
        self._fields.3 = Option::Some(value.into());
        CreateReportBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CreateReportBuilder<St, S>
where
    St: create_report_state::State,
    St::ReasonType: create_report_state::IsSet,
    St::Subject: create_report_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CreateReport<S> {
        CreateReport {
            mod_tool: self._fields.0,
            reason: self._fields.1,
            reason_type: self._fields.2.unwrap(),
            subject: self._fields.3.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>>,
    ) -> CreateReport<S> {
        CreateReport {
            mod_tool: self._fields.0,
            reason: self._fields.1,
            reason_type: self._fields.2.unwrap(),
            subject: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_moderation_createReport() -> 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("com.atproto.moderation.createReport"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcProcedure(LexXrpcProcedure {
                    input: Some(LexXrpcBody {
                        encoding: CowStr::new_static("application/json"),
                        schema: Some(
                            LexXrpcBodySchema::Object(LexObject {
                                required: Some(
                                    vec![
                                        SmolStr::new_static("reasonType"),
                                        SmolStr::new_static("subject")
                                    ],
                                ),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("modTool"),
                                        LexObjectProperty::Ref(LexRef {
                                            r#ref: CowStr::new_static("#modTool"),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("reason"),
                                        LexObjectProperty::String(LexString {
                                            description: Some(
                                                CowStr::new_static(
                                                    "Additional context about the content and violation.",
                                                ),
                                            ),
                                            max_length: Some(20000usize),
                                            max_graphemes: Some(2000usize),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("reasonType"),
                                        LexObjectProperty::Ref(LexRef {
                                            r#ref: CowStr::new_static(
                                                "com.atproto.moderation.defs#reasonType",
                                            ),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("subject"),
                                        LexObjectProperty::Union(LexRefUnion {
                                            refs: vec![
                                                CowStr::new_static("com.atproto.admin.defs#repoRef"),
                                                CowStr::new_static("com.atproto.repo.strongRef")
                                            ],
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("modTool"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Moderation tool information for tracing the source of the action",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("name")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("meta"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Name/identifier of the source (e.g., 'bsky-app/android', 'bsky-web/chrome')",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}