// <auto-generated/>
// ReSharper disable All

namespace MyTelegram.Schema;

///<summary>
/// Describes a <a href="https://corefork.telegram.org/api/business#away-messages">Telegram Business away message</a>, automatically sent to users writing to us when we're offline, during closing hours, while we're on vacation, or in some other custom time period when we cannot immediately answer to the user.
/// See <a href="https://corefork.telegram.org/constructor/businessAwayMessage" />
///</summary>
[TlObject(0xef156a5c)]
public sealed class TBusinessAwayMessage : IBusinessAwayMessage
{
    public uint ConstructorId => 0xef156a5c;
    ///<summary>
    /// Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a>
    ///</summary>
    public int Flags { get; set; }

    ///<summary>
    /// If set, the messages will not be sent if the account was online in the last 10 minutes.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool OfflineOnly { get; set; }

    ///<summary>
    /// ID of a <a href="https://corefork.telegram.org/api/business#quick-reply-shortcuts">quick reply shorcut, containing the away messages to send, see here » for more info</a>.
    ///</summary>
    public int ShortcutId { get; set; }

    ///<summary>
    /// Specifies when should the away messages be sent.
    /// See <a href="https://corefork.telegram.org/type/BusinessAwayMessageSchedule" />
    ///</summary>
    public MyTelegram.Schema.IBusinessAwayMessageSchedule Schedule { get; set; }

    ///<summary>
    /// Allowed recipients for the away messages.
    /// See <a href="https://corefork.telegram.org/type/BusinessRecipients" />
    ///</summary>
    public MyTelegram.Schema.IBusinessRecipients Recipients { get; set; }

    public void ComputeFlag()
    {
        if (OfflineOnly) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(ShortcutId);
        writer.Write(Schedule);
        writer.Write(Recipients);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { OfflineOnly = true; }
        ShortcutId = buffer.ReadInt32();
        Schedule = buffer.Read<MyTelegram.Schema.IBusinessAwayMessageSchedule>();
        Recipients = buffer.Read<MyTelegram.Schema.IBusinessRecipients>();
    }
}