// Copyright Epic Games, Inc. All Rights Reserved. using System.Collections.Generic; using System.Text.Json.Serialization; using EpicGames.Slack.Elements; namespace EpicGames.Slack.Blocks { /// /// Represents a BlockKit Section block /// public class SectionBlock : Block { /// /// The text for the block, in the form of a text object. Maximum length for the text in this field is 3000 characters. /// [JsonPropertyName("text"), JsonPropertyOrder(1)] public TextObject? Text { get; set; } /// /// Required if no text is provided. An array of text objects. Any text objects included with fields will be rendered in a compact format that allows for 2 columns of side-by-side text. /// Maximum number of items is 10. Maximum length for the text in each item is 2000 characters. /// [JsonPropertyName("fields"), JsonPropertyOrder(2)] public IReadOnlyList? Fields { get; set; } /// /// One of the available element objects. /// [JsonPropertyName("accessory"), JsonPropertyOrder(3)] public Element? Accessory { get; set; } /// /// Constructor /// /// Any text to initiale the Section with /// Optional accessory element public SectionBlock(TextObject text, Element? accessory = null) : base("section") { Text = text; Accessory = accessory; } /// /// Constructor /// /// Any text to initiale the Section with /// Optional accessory element public SectionBlock(List fields, Element? accessory = null) : base("section") { Fields = fields; Accessory = accessory; } } /// /// Extension methods for /// public static class SectionBlockExtensions { /// /// Adds a new with a single text element to the container. /// The block container to add the section to /// The text content to populate the section with /// public static void AddSection(this ISlackBlockContainer container, TextObject text) { SectionBlock block = new (text); container.Blocks.Add(block); } /// /// Adds a new with multiple field elements to the container /// The block container to add the section to /// The list of text fields to populate the section with /// public static void AddSection(this ISlackBlockContainer container, List fields) { SectionBlock block = new (fields); container.Blocks.Add(block); } } }