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

namespace MyTelegram.Schema;

///<summary>
/// Specifies a set of <a href="https://corefork.telegram.org/api/business#opening-hours">Telegram Business opening hours</a>.
/// See <a href="https://corefork.telegram.org/constructor/businessWorkHours" />
///</summary>
[TlObject(0x8c92b098)]
public sealed class TBusinessWorkHours : IBusinessWorkHours
{
    public uint ConstructorId => 0x8c92b098;
    ///<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>
    /// Ignored if set while invoking <a href="https://corefork.telegram.org/method/account.updateBusinessWorkHours">account.updateBusinessWorkHours</a>, only returned by the server in <a href="https://corefork.telegram.org/constructor/userFull">userFull</a>.<code>business_work_hours</code>, indicating whether the business is currently open according to the current time and the values in <code>weekly_open</code> and <code>timezone</code>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool OpenNow { get; set; }

    ///<summary>
    /// An ID of one of the timezones returned by <a href="https://corefork.telegram.org/method/help.getTimezonesList">help.getTimezonesList</a>.  <br>  The timezone ID is contained <a href="https://corefork.telegram.org/constructor/timezone">timezone</a>.<code>id</code>, a human-readable, localized name of the timezone is available in <a href="https://corefork.telegram.org/constructor/timezone">timezone</a>.<code>name</code> and the <a href="https://corefork.telegram.org/constructor/timezone">timezone</a>.<code>utc_offset</code> field contains the UTC offset in seconds, which may be displayed in hh:mm format by the client together with the human-readable name (i.e. <code>$name UTC -01:00</code>).
    ///</summary>
    public string TimezoneId { get; set; }

    ///<summary>
    /// A list of time intervals (max 28) represented by <a href="https://corefork.telegram.org/constructor/businessWeeklyOpen">businessWeeklyOpen »</a>, indicating the opening hours of their business.
    ///</summary>
    public TVector<MyTelegram.Schema.IBusinessWeeklyOpen> WeeklyOpen { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(TimezoneId);
        writer.Write(WeeklyOpen);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { OpenNow = true; }
        TimezoneId = buffer.ReadString();
        WeeklyOpen = buffer.Read<TVector<MyTelegram.Schema.IBusinessWeeklyOpen>>();
    }
}