"""
`/api/notes/` — the fourth slice.

List, create, patch, delete, `bulk` and `sample` all come from the base and the
two mixins. Two things here are specific to Notes, and the first is a cost this
feature has and no other does.

**A NOTE IS THE BIGGEST ROW IN THE APP, AND THE LIST ENDPOINT RETURNS ALL OF
IT.** `sheets` holds the whole document, so a page of forty notes is forty
documents on the wire for a grid that draws six preview blocks each. This is
left as it is, deliberately: the client's `listNotes` feeds `NotesPage` AND the
editor, the editor opens from the cached list rather than re-fetching, and a
list that dropped `sheets` would make opening a note a second round trip on the
one interaction that has to feel instant. On a 1 GB box the guard is the
paginator — `PAGE_SIZE` is 200, and a `page_size=` query is what a grid should
send the day somebody's page really has four hundred notes on it.

The two calendar links are selected with the row. A note that was added to a
calendar carries two pointers, and resolving them per row is the N+1 that only
shows up once there is real data.
"""

from ..mixins import BulkReplaceMixin, PageScopedViewSet, SampleMixin
from ..models import Note
from ..samples.notes import sample_notes
from ..serializers.notes import NoteSerializer


class NoteViewSet(BulkReplaceMixin, SampleMixin, PageScopedViewSet):
    queryset = Note.objects.select_related('calendar_page', 'calendar_event')
    serializer_class = NoteSerializer
    bulk_key = 'notes'
    sample_factory = staticmethod(sample_notes)
