// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.

package bsky

// schema: app.bsky.bookmark.defs

import (
	"encoding/json"
	"fmt"

	comatprototypes "github.com/bluesky-social/indigo/api/atproto"
	"github.com/bluesky-social/indigo/lex/util"
)

// BookmarkDefs_Bookmark is a "bookmark" in the app.bsky.bookmark.defs schema.
//
// Object used to store bookmark data in stash.
type BookmarkDefs_Bookmark struct {
	// subject: A strong ref to the record to be bookmarked. Currently, only `app.bsky.feed.post` records are supported.
	Subject *comatprototypes.RepoStrongRef `json:"subject" cborgen:"subject"`
}

// BookmarkDefs_BookmarkView is a "bookmarkView" in the app.bsky.bookmark.defs schema.
type BookmarkDefs_BookmarkView struct {
	CreatedAt *string                         `json:"createdAt,omitempty" cborgen:"createdAt,omitempty"`
	Item      *BookmarkDefs_BookmarkView_Item `json:"item" cborgen:"item"`
	// subject: A strong ref to the bookmarked record.
	Subject *comatprototypes.RepoStrongRef `json:"subject" cborgen:"subject"`
}

type BookmarkDefs_BookmarkView_Item struct {
	FeedDefs_BlockedPost  *FeedDefs_BlockedPost
	FeedDefs_NotFoundPost *FeedDefs_NotFoundPost
	FeedDefs_PostView     *FeedDefs_PostView
}

func (t *BookmarkDefs_BookmarkView_Item) MarshalJSON() ([]byte, error) {
	if t.FeedDefs_BlockedPost != nil {
		t.FeedDefs_BlockedPost.LexiconTypeID = "app.bsky.feed.defs#blockedPost"
		return json.Marshal(t.FeedDefs_BlockedPost)
	}
	if t.FeedDefs_NotFoundPost != nil {
		t.FeedDefs_NotFoundPost.LexiconTypeID = "app.bsky.feed.defs#notFoundPost"
		return json.Marshal(t.FeedDefs_NotFoundPost)
	}
	if t.FeedDefs_PostView != nil {
		t.FeedDefs_PostView.LexiconTypeID = "app.bsky.feed.defs#postView"
		return json.Marshal(t.FeedDefs_PostView)
	}
	return nil, fmt.Errorf("cannot marshal empty enum")
}
func (t *BookmarkDefs_BookmarkView_Item) UnmarshalJSON(b []byte) error {
	typ, err := util.TypeExtract(b)
	if err != nil {
		return err
	}

	switch typ {
	case "app.bsky.feed.defs#blockedPost":
		t.FeedDefs_BlockedPost = new(FeedDefs_BlockedPost)
		return json.Unmarshal(b, t.FeedDefs_BlockedPost)
	case "app.bsky.feed.defs#notFoundPost":
		t.FeedDefs_NotFoundPost = new(FeedDefs_NotFoundPost)
		return json.Unmarshal(b, t.FeedDefs_NotFoundPost)
	case "app.bsky.feed.defs#postView":
		t.FeedDefs_PostView = new(FeedDefs_PostView)
		return json.Unmarshal(b, t.FeedDefs_PostView)

	default:
		return nil
	}
}
