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 virtual BlockType Type { get ; set ; }
27+
28+ [ JsonProperty ( "created_time" ) ]
29+ public string CreatedTime { get ; set ; }
30+
31+ [ JsonProperty ( "last_edited_time" ) ]
32+ public string LastEditedTime { get ; set ; }
33+
34+ [ JsonProperty ( "has_children" ) ]
35+ public virtual bool HasChildren { get ; set ; }
36+ }
37+
38+ public class ParagraphBlock : BlockBase
39+ {
40+ public override BlockType Type => BlockType . Paragraph ;
41+
42+ public ParagraphClass Paragraph { get ; set ; }
43+
44+ public class ParagraphClass
45+ {
46+ public IEnumerable < RichTextBase > Text { get ; set ; }
47+ public IEnumerable < BlockBase > Children { get ; set ; }
48+ }
49+ }
50+
51+ public class HeadingOneBlock : BlockBase
52+ {
53+ public override BlockType Type => BlockType . Heading_1 ;
54+
55+ [ JsonProperty ( "heading_1" ) ]
56+ public HeadingOneClass Heading_1 { get ; set ; }
57+
58+ public override bool HasChildren => false ;
59+
60+ public class HeadingOneClass
61+ {
62+ public IEnumerable < RichTextBase > Text { get ; set ; }
63+ }
64+ }
65+
66+ public class HeadingTwoBlock : BlockBase
67+ {
68+ public override BlockType Type => BlockType . Heading_2 ;
69+
70+ [ JsonProperty ( "heading_2" ) ]
71+ public HeadingTwoClass Heading_2 { get ; set ; }
72+
73+ public override bool HasChildren => false ;
74+
75+ public class HeadingTwoClass
76+ {
77+ public IEnumerable < RichTextBase > Text { get ; set ; }
78+ }
79+ }
80+
81+ public class HeadingThreeeBlock : BlockBase
82+ {
83+ public override BlockType Type => BlockType . Heading_3 ;
84+
85+ [ JsonProperty ( "heading_3" ) ]
86+ public HeadingThreeClass Heading_3 { get ; set ; }
87+
88+ public override bool HasChildren => false ;
89+
90+ public class HeadingThreeClass
91+ {
92+ public IEnumerable < RichTextBase > Text { get ; set ; }
93+ }
94+ }
95+
96+ public class BulletedListItemBlock : BlockBase
97+ {
98+ public override BlockType Type => BlockType . BulletedListItem ;
99+
100+ [ JsonProperty ( "bulleted_list_item" ) ]
101+ public BulletedListItemClass BulletedListItem { get ; set ; }
102+
103+ public class BulletedListItemClass
104+ {
105+ public IEnumerable < RichTextBase > Text { get ; set ; }
106+ public IEnumerable < BlockBase > Children { get ; set ; }
107+ }
108+ }
109+
110+ public class NumberedListItemBlock : BlockBase
111+ {
112+ public override BlockType Type => BlockType . NumberedListItem ;
113+
114+ [ JsonProperty ( "numbered_list_item" ) ]
115+ public NumberedListItemClass NumberedListItem { get ; set ; }
116+
117+ public class NumberedListItemClass
118+ {
119+ public IEnumerable < RichTextBase > Text { get ; set ; }
120+ public IEnumerable < BlockBase > Children { get ; set ; }
121+ }
122+ }
123+
124+ public class ToDoBlock : BlockBase
125+ {
126+ public override BlockType Type => BlockType . ToDo ;
127+
128+ [ JsonProperty ( "to_do" ) ]
129+ public ToDoClass ToDo { get ; set ; }
130+
131+ public class ToDoClass
132+ {
133+ public IEnumerable < RichTextBase > Text { get ; set ; }
134+
135+ [ JsonProperty ( "checked" ) ]
136+ public bool IsChecked { get ; set ; }
137+
138+ public IEnumerable < BlockBase > Children { get ; set ; }
139+ }
140+ }
141+
142+ public class ToggleBlock : BlockBase
143+ {
144+ public override BlockType Type => BlockType . Toggle ;
145+
146+ public ToggleClass Toggle { get ; set ; }
147+
148+ public class ToggleClass
149+ {
150+ public IEnumerable < RichTextBase > Text { get ; set ; }
151+ public IEnumerable < BlockBase > Children { get ; set ; }
152+ }
153+ }
154+
155+ public class ChildPageBlock : BlockBase
156+ {
157+ public override BlockType Type => BlockType . ChildPage ;
158+
159+ [ JsonProperty ( "child_page" ) ]
160+ public ChildPageClass ChildPage { get ; set ; }
161+
162+ public class ChildPageClass
163+ {
164+ public string Title { get ; set ; }
165+ }
166+ }
167+
168+ public class UnsupportedBlock : BlockBase
169+ {
170+ public override BlockType Type => BlockType . Unsupported ;
171+ }
172+
173+ public enum BlockType
174+ {
175+ [ EnumMember ( Value = "paragraph" ) ]
176+ Paragraph ,
177+
178+ [ EnumMember ( Value = "heading_1" ) ]
179+ Heading_1 ,
180+
181+ [ EnumMember ( Value = "heading_2" ) ]
182+ Heading_2 ,
183+
184+ [ EnumMember ( Value = "heading_3" ) ]
185+ Heading_3 ,
186+
187+ [ EnumMember ( Value = "bulleted_list_item" ) ]
188+ BulletedListItem ,
189+
190+ [ EnumMember ( Value = "numbered_list_item" ) ]
191+ NumberedListItem ,
192+
193+ [ EnumMember ( Value = "to_do" ) ]
194+ ToDo ,
195+
196+ [ EnumMember ( Value = "toggle" ) ]
197+ Toggle ,
198+
199+ [ EnumMember ( Value = "child_page" ) ]
200+ ChildPage ,
201+
202+ [ EnumMember ( Value = "unsupported" ) ]
203+ Unsupported
204+ }
205+ }
0 commit comments