package models import ( "fmt" "io" ) // ChapterCommentMode represents the kind of tags. type ChapterCommentMode string const ( // ChapterCommentModeDisabled is a chapter comment mode, see GraphQL documentation. ChapterCommentModeDisabled ChapterCommentMode = "Disabled" // ChapterCommentModeArticle is a chapter comment mode, see GraphQL documentation. ChapterCommentModeArticle ChapterCommentMode = "Article" // ChapterCommentModeChat is a chapter comment mode, see GraphQL documentation. ChapterCommentModeChat ChapterCommentMode = "Chat" // ChapterCommentModeMessage is a chapter comment mode, see GraphQL documentation. ChapterCommentModeMessage ChapterCommentMode = "Message" ) // UnmarshalGQL unmarshals func (e *ChapterCommentMode) UnmarshalGQL(v interface{}) error { str, ok := v.(string) if !ok { return fmt.Errorf("enums must be strings") } *e = ChapterCommentMode(str) switch *e { case ChapterCommentModeDisabled, ChapterCommentModeArticle, ChapterCommentModeChat, ChapterCommentModeMessage: return nil default: return fmt.Errorf("%s is not a valid ChapterCommentMode", str) } } // IsEnabled returns true if comments are enabled. func (e ChapterCommentMode) IsEnabled() bool { return e != ChapterCommentModeDisabled && len(e) != 0 } // MarshalGQL turns it into a JSON string func (e ChapterCommentMode) MarshalGQL(w io.Writer) { // Backwards compatibility: Empty value means disabled. if len(e) == 0 { w.Write(disabledChapterCommentModeBytes) return } fmt.Fprint(w, "\""+string(e)+"\"") } var disabledChapterCommentModeBytes = []byte(`"Disabled"`)