use serde::{Deserialize, Serialize};
use crate::{
api::{Form, Method, Payload},
types::{
AcceptedGiftTypes,
Chat,
InputProfilePhoto,
InputProfilePhotoError,
InputStoryContent,
InputStoryContentError,
Integer,
Location,
ParseMode,
StarAmount,
Sticker,
Story,
StoryAreas,
StoryAreasError,
TextEntities,
TextEntity,
TextEntityError,
User,
},
};
#[serde_with::skip_serializing_none]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct BusinessBotRights {
pub can_change_gift_settings: Option<bool>,
pub can_convert_gifts_to_stars: Option<bool>,
pub can_delete_all_messages: Option<bool>,
pub can_delete_outgoing_messages: Option<bool>,
pub can_edit_bio: Option<bool>,
pub can_edit_name: Option<bool>,
pub can_edit_profile_photo: Option<bool>,
pub can_edit_username: Option<bool>,
pub can_manage_stories: Option<bool>,
pub can_read_messages: Option<bool>,
pub can_reply: Option<bool>,
pub can_transfer_and_upgrade_gifts: Option<bool>,
pub can_transfer_stars: Option<bool>,
pub can_view_gifts_and_stars: Option<bool>,
}
impl BusinessBotRights {
pub fn with_can_change_gift_settings(mut self, value: bool) -> Self {
self.can_change_gift_settings = Some(value);
self
}
pub fn with_can_convert_gifts_to_stars(mut self, value: bool) -> Self {
self.can_convert_gifts_to_stars = Some(value);
self
}
pub fn with_can_delete_all_messages(mut self, value: bool) -> Self {
self.can_delete_all_messages = Some(value);
self
}
pub fn with_can_delete_outgoing_messages(mut self, value: bool) -> Self {
self.can_delete_outgoing_messages = Some(value);
self
}
pub fn with_can_edit_bio(mut self, value: bool) -> Self {
self.can_edit_bio = Some(value);
self
}
pub fn with_can_edit_name(mut self, value: bool) -> Self {
self.can_edit_name = Some(value);
self
}
pub fn with_can_edit_profile_photo(mut self, value: bool) -> Self {
self.can_edit_profile_photo = Some(value);
self
}
pub fn with_can_edit_username(mut self, value: bool) -> Self {
self.can_edit_username = Some(value);
self
}
pub fn with_can_manage_stories(mut self, value: bool) -> Self {
self.can_manage_stories = Some(value);
self
}
pub fn with_can_read_messages(mut self, value: bool) -> Self {
self.can_read_messages = Some(value);
self
}
pub fn with_can_reply(mut self, value: bool) -> Self {
self.can_reply = Some(value);
self
}
pub fn with_can_transfer_and_upgrade_gifts(mut self, value: bool) -> Self {
self.can_transfer_and_upgrade_gifts = Some(value);
self
}
pub fn with_can_transfer_stars(mut self, value: bool) -> Self {
self.can_transfer_stars = Some(value);
self
}
pub fn with_can_view_gifts_and_stars(mut self, value: bool) -> Self {
self.can_view_gifts_and_stars = Some(value);
self
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct BusinessConnection {
pub date: Integer,
pub id: String,
pub is_enabled: bool,
pub user: User,
pub user_chat_id: Integer,
pub rights: Option<BusinessBotRights>,
}
impl BusinessConnection {
pub fn new<T>(date: Integer, id: T, user: User, user_chat_id: Integer) -> Self
where
T: Into<String>,
{
Self {
date,
id: id.into(),
is_enabled: false,
user,
user_chat_id,
rights: None,
}
}
pub fn with_is_enabled(mut self, value: bool) -> Self {
self.is_enabled = value;
self
}
pub fn with_rights(mut self, value: BusinessBotRights) -> Self {
self.rights = Some(value);
self
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Default, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct BusinessIntro {
pub message: Option<String>,
pub sticker: Option<Sticker>,
pub title: Option<String>,
}
impl BusinessIntro {
pub fn with_message<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.message = Some(value.into());
self
}
pub fn with_sticker(mut self, value: Sticker) -> Self {
self.sticker = Some(value);
self
}
pub fn with_title<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.title = Some(value.into());
self
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct BusinessLocation {
pub address: String,
pub location: Option<Location>,
}
impl BusinessLocation {
pub fn new<T>(address: T) -> Self
where
T: Into<String>,
{
Self {
address: address.into(),
location: None,
}
}
pub fn with_location(mut self, value: Location) -> Self {
self.location = Some(value);
self
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct BusinessMessagesDeleted {
pub business_connection_id: String,
pub chat: Chat,
pub message_ids: Vec<Integer>,
}
impl BusinessMessagesDeleted {
pub fn new<A, B, C>(business_connection_id: A, chat: B, message_ids: C) -> Self
where
A: Into<String>,
B: Into<Chat>,
C: IntoIterator<Item = Integer>,
{
Self {
business_connection_id: business_connection_id.into(),
chat: chat.into(),
message_ids: message_ids.into_iter().collect(),
}
}
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct BusinessOpeningHoursInterval {
pub opening_minute: Integer,
pub closing_minute: Integer,
}
impl BusinessOpeningHoursInterval {
pub fn new(opening_minute: Integer, closing_minute: Integer) -> Self {
Self {
opening_minute,
closing_minute,
}
}
}
impl From<(Integer, Integer)> for BusinessOpeningHoursInterval {
fn from((opening_minute, closing_minute): (Integer, Integer)) -> Self {
Self::new(opening_minute, closing_minute)
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct BusinessOpeningHours {
pub time_zone_name: String,
pub opening_hours: Vec<BusinessOpeningHoursInterval>,
}
impl BusinessOpeningHours {
pub fn new<A, B, C>(time_zone_name: A, opening_hours: B) -> Self
where
A: Into<String>,
B: IntoIterator<Item = C>,
C: Into<BusinessOpeningHoursInterval>,
{
Self {
time_zone_name: time_zone_name.into(),
opening_hours: opening_hours.into_iter().map(Into::into).collect(),
}
}
}
#[derive(Clone, Debug, Serialize)]
pub struct ConvertGiftToStars {
business_connection_id: String,
owned_gift_id: String,
}
impl ConvertGiftToStars {
pub fn new<A, B>(business_connection_id: A, owned_gift_id: B) -> Self
where
A: Into<String>,
B: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
owned_gift_id: owned_gift_id.into(),
}
}
}
impl Method for ConvertGiftToStars {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("convertGiftToStars", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct DeleteBusinessMessages {
business_connection_id: String,
message_ids: Vec<Integer>,
}
impl DeleteBusinessMessages {
pub fn new<A, B>(business_connection_id: A, message_ids: B) -> Self
where
A: Into<String>,
B: IntoIterator<Item = Integer>,
{
Self {
business_connection_id: business_connection_id.into(),
message_ids: message_ids.into_iter().collect(),
}
}
}
impl Method for DeleteBusinessMessages {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("deleteBusinessMessages", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct DeleteStory {
business_connection_id: String,
story_id: Integer,
}
impl DeleteStory {
pub fn new<T>(business_connection_id: T, story_id: Integer) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
story_id,
}
}
}
impl Method for DeleteStory {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("deleteStory", self)
}
}
pub struct EditStory {
form: Form,
}
impl EditStory {
pub fn new<A, B>(business_connection_id: A, content: B, story_id: Integer) -> Result<Self, InputStoryContentError>
where
A: Into<String>,
B: Into<InputStoryContent>,
{
let mut form: Form = content.into().try_into()?;
form.insert_field("business_connection_id", business_connection_id.into());
form.insert_field("story_id", story_id);
Ok(Self { form })
}
pub fn with_areas<T>(mut self, value: T) -> Result<Self, StoryAreasError>
where
T: Into<StoryAreas>,
{
let value = value.into().serialize()?;
self.form.insert_field("areas", value);
Ok(self)
}
pub fn with_caption<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.form.insert_field("caption", value.into());
self
}
pub fn with_caption_entities<T>(mut self, value: T) -> Result<Self, TextEntityError>
where
T: IntoIterator<Item = TextEntity>,
{
let value = TextEntities::from_iter(value);
let value = value.serialize()?;
self.form.remove_field("parse_mode");
self.form.insert_field("caption_entities", value);
Ok(self)
}
pub fn with_parse_mode(mut self, value: ParseMode) -> Self {
self.form.remove_field("caption_entities");
self.form.insert_field("parse_mode", value);
self
}
}
impl Method for EditStory {
type Response = Story;
fn into_payload(self) -> Payload {
Payload::form("editStory", self.form)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct GetBusinessAccountStarBalance {
business_connection_id: String,
}
impl GetBusinessAccountStarBalance {
pub fn new<T>(business_connection_id: T) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
}
}
}
impl Method for GetBusinessAccountStarBalance {
type Response = StarAmount;
fn into_payload(self) -> Payload {
Payload::json("getBusinessAccountStarBalance", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct GetBusinessConnection {
business_connection_id: String,
}
impl GetBusinessConnection {
pub fn new<T>(business_connection_id: T) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
}
}
}
impl Method for GetBusinessConnection {
type Response = BusinessConnection;
fn into_payload(self) -> Payload {
Payload::json("getBusinessConnection", self)
}
}
pub struct PostStory {
form: Form,
}
impl PostStory {
pub fn new<A, B>(
active_period: Integer,
business_connection_id: A,
content: B,
) -> Result<Self, InputStoryContentError>
where
A: Into<String>,
B: Into<InputStoryContent>,
{
let mut form: Form = content.into().try_into()?;
form.insert_field("active_period", active_period);
form.insert_field("business_connection_id", business_connection_id.into());
Ok(Self { form })
}
pub fn with_areas<T>(mut self, value: T) -> Result<Self, StoryAreasError>
where
T: Into<StoryAreas>,
{
let value = value.into().serialize()?;
self.form.insert_field("areas", value);
Ok(self)
}
pub fn with_caption<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.form.insert_field("caption", value.into());
self
}
pub fn with_caption_entities<T>(mut self, value: T) -> Result<Self, TextEntityError>
where
T: IntoIterator<Item = TextEntity>,
{
let value = TextEntities::from_iter(value);
let value = value.serialize()?;
self.form.remove_field("parse_mode");
self.form.insert_field("caption_entities", value);
Ok(self)
}
pub fn with_parse_mode(mut self, value: ParseMode) -> Self {
self.form.remove_field("caption_entities");
self.form.insert_field("parse_mode", value);
self
}
pub fn with_post_to_chat_page(mut self, value: bool) -> Self {
self.form.insert_field("post_to_chat_page", value);
self
}
pub fn with_protect_content(mut self, value: bool) -> Self {
self.form.insert_field("protect_content", value);
self
}
}
impl Method for PostStory {
type Response = Story;
fn into_payload(self) -> Payload {
Payload::form("postStory", self.form)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct ReadBusinessMessage {
business_connection_id: String,
chat_id: Integer,
message_id: Integer,
}
impl ReadBusinessMessage {
pub fn new<T>(business_connection_id: T, chat_id: Integer, message_id: Integer) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
chat_id,
message_id,
}
}
}
impl Method for ReadBusinessMessage {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("readBusinessMessage", self)
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct RemoveBusinessAccountProfilePhoto {
business_connection_id: String,
is_public: Option<bool>,
}
impl RemoveBusinessAccountProfilePhoto {
pub fn new<T>(business_connection_id: T) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
is_public: None,
}
}
pub fn with_is_public(mut self, value: bool) -> Self {
self.is_public = Some(value);
self
}
}
impl Method for RemoveBusinessAccountProfilePhoto {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("removeBusinessAccountProfilePhoto", self)
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct SetBusinessAccountBio {
business_connection_id: String,
bio: Option<String>,
}
impl SetBusinessAccountBio {
pub fn new<T>(business_connection_id: T) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
bio: None,
}
}
pub fn with_bio<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.bio = Some(value.into());
self
}
}
impl Method for SetBusinessAccountBio {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("setBusinessAccountBio", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct SetBusinessAccountGiftSettings {
accepted_gift_types: AcceptedGiftTypes,
business_connection_id: String,
show_gift_button: bool,
}
impl SetBusinessAccountGiftSettings {
pub fn new<T>(business_connection_id: T, show_gift_button: bool, accepted_gift_types: AcceptedGiftTypes) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
show_gift_button,
accepted_gift_types,
}
}
}
impl Method for SetBusinessAccountGiftSettings {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("setBusinessAccountGiftSettings", self)
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct SetBusinessAccountName {
business_connection_id: String,
first_name: String,
last_name: Option<String>,
}
impl SetBusinessAccountName {
pub fn new<A, B>(business_connection_id: A, first_name: B) -> Self
where
A: Into<String>,
B: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
first_name: first_name.into(),
last_name: None,
}
}
pub fn with_last_name<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.last_name = Some(value.into());
self
}
}
impl Method for SetBusinessAccountName {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("setBusinessAccountName", self)
}
}
#[derive(Debug)]
pub struct SetBusinessAccountProfilePhoto {
form: Form,
}
impl SetBusinessAccountProfilePhoto {
pub fn new<A, B>(business_connection_id: A, photo: B) -> Result<Self, InputProfilePhotoError>
where
A: Into<String>,
B: Into<InputProfilePhoto>,
{
let mut form = Form::try_from(photo.into())?;
form.insert_field("business_connection_id", business_connection_id.into());
Ok(Self { form })
}
pub fn with_is_public(mut self, value: bool) -> Self {
self.form.insert_field("is_public", value);
self
}
}
impl Method for SetBusinessAccountProfilePhoto {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::form("setBusinessAccountProfilePhoto", self.form)
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct SetBusinessAccountUsername {
business_connection_id: String,
username: Option<String>,
}
impl SetBusinessAccountUsername {
pub fn new<T>(business_connection_id: T) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
username: None,
}
}
pub fn with_username<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.username = Some(value.into());
self
}
}
impl Method for SetBusinessAccountUsername {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("setBusinessAccountUsername", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct TransferBusinessAccountStars {
business_connection_id: String,
star_count: Integer,
}
impl TransferBusinessAccountStars {
pub fn new<T>(business_connection_id: T, star_count: Integer) -> Self
where
T: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
star_count,
}
}
}
impl Method for TransferBusinessAccountStars {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("transferBusinessAccountStars", self)
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct TransferGift {
business_connection_id: String,
owned_gift_id: String,
new_owner_chat_id: Integer,
star_count: Option<Integer>,
}
impl TransferGift {
pub fn new<A, B>(business_connection_id: A, owned_gift_id: B, new_owner_chat_id: Integer) -> Self
where
A: Into<String>,
B: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
owned_gift_id: owned_gift_id.into(),
new_owner_chat_id,
star_count: None,
}
}
pub fn with_star_count(mut self, value: Integer) -> Self {
self.star_count = Some(value);
self
}
}
impl Method for TransferGift {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("transferGift", self)
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct UpgradeGift {
business_connection_id: String,
owned_gift_id: String,
keep_original_details: Option<bool>,
star_count: Option<Integer>,
}
impl UpgradeGift {
pub fn new<A, B>(business_connection_id: A, owned_gift_id: B) -> Self
where
A: Into<String>,
B: Into<String>,
{
Self {
business_connection_id: business_connection_id.into(),
owned_gift_id: owned_gift_id.into(),
keep_original_details: None,
star_count: None,
}
}
pub fn with_keep_original_details(mut self, value: bool) -> Self {
self.keep_original_details = Some(value);
self
}
pub fn with_star_count(mut self, value: Integer) -> Self {
self.star_count = Some(value);
self
}
}
impl Method for UpgradeGift {
type Response = bool;
fn into_payload(self) -> Payload {
Payload::json("upgradeGift", self)
}
}