2021-12-09 17:57:08 +01:00
|
|
|
package notion
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
type IconType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
IconTypeEmoji IconType = "emoji"
|
2021-12-20 19:54:19 +01:00
|
|
|
IconTypeFile IconType = "file"
|
2021-12-09 17:57:08 +01:00
|
|
|
IconTypeExternal IconType = "external"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Icon has one non-nil Emoji or External field, denoted by the corresponding
|
|
|
|
// IconType.
|
|
|
|
type Icon struct {
|
|
|
|
Type IconType `json:"type"`
|
|
|
|
|
|
|
|
Emoji *string `json:"emoji,omitempty"`
|
2021-12-20 20:12:44 +01:00
|
|
|
File *FileFile `json:"file,omitempty"`
|
|
|
|
External *FileExternal `json:"external,omitempty"`
|
2021-12-09 17:57:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (icon Icon) Validate() error {
|
|
|
|
if icon.Type == "" {
|
|
|
|
return errors.New("icon type cannot be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if icon.Type == IconTypeEmoji && icon.Emoji == nil {
|
|
|
|
return errors.New("icon emoji cannot be empty")
|
|
|
|
}
|
|
|
|
if icon.Type == IconTypeExternal && icon.External == nil {
|
|
|
|
return errors.New("icon external cannot be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|