use serde::{Deserialize, Serialize};
use crate::{
api::{Form, Method, Payload, PayloadError, WriteForm},
types::{
AcceptedGiftTypes,
Chat,
InputProfilePhoto,
InputProfilePhotoData,
InputStoryContent,
InputStoryContentData,
InputTextCaption,
Integer,
Location,
StarAmount,
Sticker,
Story,
StoryAreas,
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_delete_sent_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>,
}
#[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>,
}
#[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>,
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct BusinessLocation {
pub address: String,
pub location: Option<Location>,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct BusinessMessagesDeleted {
pub business_connection_id: String,
pub chat: Chat,
pub message_ids: Vec<Integer>,
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct BusinessOpeningHoursInterval {
pub opening_minute: Integer,
pub closing_minute: Integer,
}
impl From<(Integer, Integer)> for BusinessOpeningHoursInterval {
fn from((opening_minute, closing_minute): (Integer, Integer)) -> Self {
Self {
opening_minute,
closing_minute,
}
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct BusinessOpeningHours {
pub time_zone_name: String,
pub opening_hours: Vec<BusinessOpeningHoursInterval>,
}
#[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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
Payload::json("deleteStory", self)
}
}
pub struct EditStory {
content: InputStoryContent,
parameters: EditStoryParameters,
}
impl EditStory {
pub fn new<A, B>(business_connection_id: A, content: B, story_id: Integer) -> Self
where
A: Into<String>,
B: Into<InputStoryContent>,
{
Self {
content: content.into(),
parameters: EditStoryParameters {
business_connection_id: Some(business_connection_id.into()),
story_id: Some(story_id),
..Default::default()
},
}
}
pub fn with_areas<T>(mut self, value: T) -> Self
where
T: Into<StoryAreas>,
{
self.parameters.areas = Some(value.into());
self
}
pub fn with_caption<T>(mut self, value: T) -> Self
where
T: Into<InputTextCaption>,
{
self.parameters.caption = Some(value.into());
self
}
}
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Serialize)]
struct EditStoryParameters {
areas: Option<StoryAreas>,
business_connection_id: Option<String>,
#[serde(flatten)]
caption: Option<InputTextCaption>,
content: Option<InputStoryContentData>,
story_id: Option<Integer>,
}
impl Method for EditStory {
type Response = Story;
fn into_payload(self) -> Result<Payload, PayloadError> {
let Self {
content,
mut parameters,
} = self;
let mut form = Form::default();
parameters.content = Some(content.write(&mut form));
parameters.serialize(&mut form)?;
Payload::form("editStory", 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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
Payload::json("getBusinessConnection", self)
}
}
pub struct PostStory {
content: InputStoryContent,
parameters: PostStoryParameters,
}
impl PostStory {
pub fn new<A, B>(active_period: Integer, business_connection_id: A, content: B) -> Self
where
A: Into<String>,
B: Into<InputStoryContent>,
{
Self {
content: content.into(),
parameters: PostStoryParameters {
active_period: Some(active_period),
business_connection_id: Some(business_connection_id.into()),
..Default::default()
},
}
}
pub fn with_areas<T>(mut self, value: T) -> Self
where
T: Into<StoryAreas>,
{
self.parameters.areas = Some(value.into());
self
}
pub fn with_caption<T>(mut self, value: T) -> Self
where
T: Into<InputTextCaption>,
{
self.parameters.caption = Some(value.into());
self
}
pub fn with_post_to_chat_page(mut self, value: bool) -> Self {
self.parameters.post_to_chat_page = Some(value);
self
}
pub fn with_protect_content(mut self, value: bool) -> Self {
self.parameters.protect_content = Some(value);
self
}
}
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Serialize)]
struct PostStoryParameters {
active_period: Option<Integer>,
areas: Option<StoryAreas>,
business_connection_id: Option<String>,
#[serde(flatten)]
caption: Option<InputTextCaption>,
content: Option<InputStoryContentData>,
post_to_chat_page: Option<bool>,
protect_content: Option<bool>,
}
impl Method for PostStory {
type Response = Story;
fn into_payload(self) -> Result<Payload, PayloadError> {
let Self {
content,
mut parameters,
} = self;
let mut form = Form::default();
parameters.content = Some(content.write(&mut form));
parameters.serialize(&mut form)?;
Payload::form("postStory", 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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
Payload::json("setBusinessAccountName", self)
}
}
#[derive(Debug)]
pub struct SetBusinessAccountProfilePhoto {
photo: InputProfilePhoto,
parameters: SetBusinessAccountProfilePhotoParameters,
}
impl SetBusinessAccountProfilePhoto {
pub fn new<A, B>(business_connection_id: A, photo: B) -> Self
where
A: Into<String>,
B: Into<InputProfilePhoto>,
{
Self {
photo: photo.into(),
parameters: SetBusinessAccountProfilePhotoParameters {
business_connection_id: Some(business_connection_id.into()),
..Default::default()
},
}
}
pub fn with_is_public(mut self, value: bool) -> Self {
self.parameters.is_public = Some(value);
self
}
}
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Serialize)]
struct SetBusinessAccountProfilePhotoParameters {
business_connection_id: Option<String>,
photo: Option<InputProfilePhotoData>,
is_public: Option<bool>,
}
impl Method for SetBusinessAccountProfilePhoto {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
let Self { photo, mut parameters } = self;
let mut form = Form::default();
parameters.photo = Some(photo.write(&mut form));
parameters.serialize(&mut form)?;
Payload::form("setBusinessAccountProfilePhoto", 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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
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) -> Result<Payload, PayloadError> {
Payload::json("upgradeGift", self)
}
}