<commit_before>use serde_json::builder::ObjectBuilder;
use serde_json::Value;
use std::default::Default;
use ::model::{ChannelId, Region, VerificationLevel};

/// A builder to optionally edit certain fields of a [`Guild`]. This is meant
/// for usage with [`Context::edit_guild`] and [`LiveGuild::edit`].
///
/// **Note**: Editing a guild requires that the current user have the
/// [Manage Guild] permission.
///
/// [`Context::edit_guild`]: ../../client/struct.Context.html
/// [`Guild`]: ../../model/struct.Guild.html
/// [`LiveGuild::edit`]: ../../model/struct.LiveGuild.html#method.edit
/// [Manage Guild]: ../../model/permissions/constant.MANAGE_GUILD.html
pub struct EditGuild(pub ObjectBuilder);

impl EditGuild {
    /// Set the "AFK voice channel" that users are to move to if they have been
    /// AFK for an amount of time, configurable by [`afk_timeout`].
    ///
    /// The given channel must be either some valid voice channel, or `None` to
    /// not set an AFK channel. The library does not check if a channel is
    /// valid.
    ///
    /// [`afk_timeout`]: #method.afk_timeout
    pub fn afk_channel<C: Into<ChannelId>>(self, channel: Option<C>) -> Self {
        EditGuild(self.0.insert("afk_channel_id", match channel {
            Some(channel) => Value::U64(channel.into().0),
            None => Value::Null,
        }))
    }

    /// Set the amount of time a user is to be moved to the AFK channel -
    /// configured via [`afk_channel`] - after being AFK.
    ///
    /// [`afk_channel`]: #method.afk_channel
    pub fn afk_timeout(self, timeout: u64) -> Self {
        EditGuild(self.0.insert("afk_timeout", timeout))
    }

    /// Set the icon of the guild. Pass `None` to remove the icon.
    ///
    /// # Examples
    ///
    /// Using the utility function - [`utils::read_image`] - to read an image
    /// from the cwd and encode it in base64 to send to Discord.
    ///
    /// ```rust,ignore
    /// use serenity::utils;
    ///
    /// // assuming a `guild` has already been bound
    ///
    /// let base64_icon = utils::read_image("./guild_icon.png")
    ///     .expect("Failed to read image");
    ///
    /// let _ = guild.edit(|g| g.icon(base64_icon));
    /// ```
    ///
    /// [`utils::read_image`]: ../../utils/fn.read_image.html
    pub fn icon(self, icon: Option<&str>) -> Self {
        EditGuild(self.0
            .insert("icon",
                    icon.map_or_else(|| Value::Null,
                                     |x| Value::String(x.to_owned()))))
    }

    /// Set the name of the guild.
    ///
    /// **Note**: Must be between (and including) 2-100 chracters.
    pub fn name(self, name: &str) -> Self {
        EditGuild(self.0.insert("name", name))
    }

    /// Set the voice region of the server.
    ///
    /// # Examples
    ///
    /// Setting the region to [`Region::UsWest`]:
    ///
    /// ```rust,ignore
    /// use serenity::model::Region;
    ///
    /// // assuming a `guild` has already been bound
    ///<commit_msg>Add method to EditGuild to transfer ownership<commit_after>use serde_json::builder::ObjectBuilder;
use serde_json::Value;
use std::default::Default;
use ::model::{ChannelId, Region, UserId, VerificationLevel};

/// A builder to optionally edit certain fields of a [`Guild`]. This is meant
/// for usage with [`Context::edit_guild`] and [`LiveGuild::edit`].
///
/// **Note**: Editing a guild requires that the current user have the
/// [Manage Guild] permission.
///
/// [`Context::edit_guild`]: ../../client/struct.Context.html
/// [`Guild`]: ../../model/struct.Guild.html
/// [`LiveGuild::edit`]: ../../model/struct.LiveGuild.html#method.edit
/// [Manage Guild]: ../../model/permissions/constant.MANAGE_GUILD.html
pub struct EditGuild(pub ObjectBuilder);

impl EditGuild {
    /// Set the "AFK voice channel" that users are to move to if they have been
    /// AFK for an amount of time, configurable by [`afk_timeout`].
    ///
    /// The given channel must be either some valid voice channel, or `None` to
    /// not set an AFK channel. The library does not check if a channel is
    /// valid.
    ///
    /// [`afk_timeout`]: #method.afk_timeout
    pub fn afk_channel<C: Into<ChannelId>>(self, channel: Option<C>) -> Self {
        EditGuild(self.0.insert("afk_channel_id", match channel {
            Some(channel) => Value::U64(channel.into().0),
            None => Value::Null,
        }))
    }

    /// Set the amount of time a user is to be moved to the AFK channel -
    /// configured via [`afk_channel`] - after being AFK.
    ///
    /// [`afk_channel`]: #method.afk_channel
    pub fn afk_timeout(self, timeout: u64) -> Self {
        EditGuild(self.0.insert("afk_timeout", timeout))
    }

    /// Set the icon of the guild. Pass `None` to remove the icon.
    ///
    /// # Examples
    ///
    /// Using the utility function - [`utils::read_image`] - to read an image
    /// from the cwd and encode it in base64 to send to Discord.
    ///
    /// ```rust,ignore
    /// use serenity::utils;
    ///
    /// // assuming a `guild` has already been bound
    ///
    /// let base64_icon = utils::read_image("./guild_icon.png")
    ///     .expect("Failed to read image");
    ///
    /// let _ = guild.edit(|g| g.icon(base64_icon));
    /// ```
    ///
    /// [`utils::read_image`]: ../../utils/fn.read_image.html
    pub fn icon(self, icon: Option<&str>) -> Self {
        EditGuild(self.0
            .insert("icon",
                    icon.map_or_else(|| Value::Null,
                                     |x| Value::String(x.to_owned()))))
    }

    /// Set the name of the guild.
    ///
    /// **Note**: Must be between (and including) 2-100 chracters.
    pub fn name(self, name: &str) -> Self {
        EditGuild(self.0.insert("name", name))
    }

    /// Transfers the ownership of the guild to another user by Id.
    ///
    /// **Note**: The current user must be the owner of the guild.
    pub fn owner<U: Into<UserId>>(self, user_id: U) -> Self {
        EditGuild(self.0.insert("owner_id", user_id.into().0))
    }

    /// Set the voice region of the server.
    ///
    /// # Examples
    ///
    /// Setting the region to [`Region::UsWest`]:
    ///
    /// ```rust,ignore
    /// use serenity::model::Region;
    ///
    /// // assuming a `guild` has already been bound
    ///
{'fraction_non_alphanumeric': 0.17522515405277295, 'fraction_numerical': 0.006320113762047717, 'mean_word_length': 2.1305637982195846, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6415682', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1955, 'n_words': 578}