1+ using System . Collections . Generic ;
2+ using System . Runtime . Serialization ;
3+ using JsonSubTypes ;
4+ using Newtonsoft . Json ;
5+ using Newtonsoft . Json . Converters ;
6+
7+ namespace Notion . Client
8+ {
9+ [ JsonConverter ( typeof ( JsonSubtypes ) , "type" ) ]
10+ [ JsonSubtypes . KnownSubType ( typeof ( BulletedListItemBlock ) , BlockType . BulletedListItem ) ]
11+ [ JsonSubtypes . KnownSubType ( typeof ( ChildPageBlock ) , BlockType . ChildPage ) ]
12+ [ JsonSubtypes . KnownSubType ( typeof ( HeadingOneBlock ) , BlockType . Heading_1 ) ]
13+ [ JsonSubtypes . KnownSubType ( typeof ( HeadingTwoBlock ) , BlockType . Heading_2 ) ]
14+ [ JsonSubtypes . KnownSubType ( typeof ( HeadingThreeeBlock ) , BlockType . Heading_3 ) ]
15+ [ JsonSubtypes . KnownSubType ( typeof ( NumberedListItemBlock ) , BlockType . NumberedListItem ) ]
16+ [ JsonSubtypes . KnownSubType ( typeof ( ParagraphBlock ) , BlockType . Paragraph ) ]
17+ [ JsonSubtypes . KnownSubType ( typeof ( ToDoBlock ) , BlockType . ToDo ) ]
18+ [ JsonSubtypes . KnownSubType ( typeof ( ToggleBlock ) , BlockType . Toggle ) ]
19+ [ JsonSubtypes . KnownSubType ( typeof ( UnsupportedBlock ) , BlockType . Unsupported ) ]
20+ public class BlockBase
21+ {
22+ public string Object => "block" ;
23+ public string Id { get ; set ; }
24+
25+ [ JsonConverter ( typeof ( StringEnumConverter ) ) ]
26+ public BlockType Type { get ; set ; }
27+
28+ [ JsonProperty ( "created_time" ) ]
29+ public string CreatedTime { get ; set ; }
30+
31+
32+ [ JsonProperty ( "last_edited_time" ) ]
33+ public string LastEditedTime { get ; set ; }
34+
35+
36+ [ JsonProperty ( "has_children" ) ]
37+ public virtual bool HasChildren { get ; set ; }
38+
39+ }
40+
41+ public class ParagraphBlock : BlockBase
42+ {
43+ public ParagraphClass Paragraph { get ; set ; }
44+
45+ public class ParagraphClass
46+ {
47+ public IEnumerable < RichTextBase > Text { get ; set ; }
48+ public IEnumerable < BlockBase > Children { get ; set ; }
49+ }
50+ }
51+
52+ public class HeadingOneBlock : BlockBase
53+ {
54+ [ JsonProperty ( "heading_1" ) ]
55+ public HeadingOneClass Heading_1 { get ; set ; }
56+
57+ public override bool HasChildren => false ;
58+
59+ public class HeadingOneClass
60+ {
61+ public IEnumerable < RichTextBase > Text { get ; set ; }
62+ }
63+ }
64+
65+ public class HeadingTwoBlock : BlockBase
66+ {
67+ [ JsonProperty ( "heading_2" ) ]
68+ public HeadingTwoClass Heading_2 { get ; set ; }
69+
70+ public override bool HasChildren => false ;
71+
72+ public class HeadingTwoClass
73+ {
74+ public IEnumerable < RichTextBase > Text { get ; set ; }
75+ }
76+ }
77+
78+ public class HeadingThreeeBlock : BlockBase
79+ {
80+ [ JsonProperty ( "heading_3" ) ]
81+ public HeadingThreeClass Heading_3 { get ; set ; }
82+
83+ public override bool HasChildren => false ;
84+
85+ public class HeadingThreeClass
86+ {
87+ public IEnumerable < RichTextBase > Text { get ; set ; }
88+ }
89+ }
90+
91+ public class BulletedListItemBlock : BlockBase
92+ {
93+ [ JsonProperty ( "bulleted_list_item" ) ]
94+ public BulletedListItemClass BulletedListItem { get ; set ; }
95+
96+ public class BulletedListItemClass
97+ {
98+ public IEnumerable < RichTextBase > Text { get ; set ; }
99+ public IEnumerable < BlockBase > Children { get ; set ; }
100+ }
101+ }
102+
103+ public class NumberedListItemBlock : BlockBase
104+ {
105+
106+ [ JsonProperty ( "numbered_list_item" ) ]
107+ public NumberedListItemClass NumberedListItem { get ; set ; }
108+
109+ public class NumberedListItemClass
110+ {
111+ public IEnumerable < RichTextBase > Text { get ; set ; }
112+ public IEnumerable < BlockBase > Children { get ; set ; }
113+ }
114+ }
115+
116+ public class ToDoBlock : BlockBase
117+ {
118+ [ JsonProperty ( "to_do" ) ]
119+ public ToDoClass ToDo { get ; set ; }
120+
121+ public class ToDoClass
122+ {
123+ public IEnumerable < RichTextBase > Text { get ; set ; }
124+
125+ [ JsonProperty ( "checked" ) ]
126+ public bool IsChecked { get ; set ; }
127+
128+ public IEnumerable < BlockBase > Children { get ; set ; }
129+ }
130+ }
131+
132+ public class ToggleBlock : BlockBase
133+ {
134+ public ToggleClass Toggle { get ; set ; }
135+
136+ public class ToggleClass
137+ {
138+ public IEnumerable < RichTextBase > Text { get ; set ; }
139+ public IEnumerable < BlockBase > Children { get ; set ; }
140+ }
141+ }
142+
143+ public class ChildPageBlock : BlockBase
144+ {
145+
146+ [ JsonProperty ( "child_page" ) ]
147+ public ChildPageClass ChildPage { get ; set ; }
148+
149+ public class ChildPageClass
150+ {
151+ public string Title { get ; set ; }
152+ }
153+ }
154+
155+ public class UnsupportedBlock : BlockBase
156+ {
157+ }
158+
159+ public enum BlockType
160+ {
161+ [ EnumMember ( Value = "paragraph" ) ]
162+ Paragraph ,
163+
164+ [ EnumMember ( Value = "heading_1" ) ]
165+ Heading_1 ,
166+
167+ [ EnumMember ( Value = "heading_2" ) ]
168+ Heading_2 ,
169+
170+ [ EnumMember ( Value = "heading_3" ) ]
171+ Heading_3 ,
172+
173+ [ EnumMember ( Value = "bulleted_list_item" ) ]
174+ BulletedListItem ,
175+
176+ [ EnumMember ( Value = "numbered_list_item" ) ]
177+ NumberedListItem ,
178+
179+ [ EnumMember ( Value = "to_do" ) ]
180+ ToDo ,
181+
182+ [ EnumMember ( Value = "toggle" ) ]
183+ Toggle ,
184+
185+ [ EnumMember ( Value = "child_page" ) ]
186+ ChildPage ,
187+
188+ [ EnumMember ( Value = "unsupported" ) ]
189+ Unsupported
190+ }
191+ }
0 commit comments