from django.db import models

# Create your models here.
from core.wagtail_utils import StrictHierarchyPage
from users.models import User


class Note(models.Model):
    text = models.TextField()


class Bookmark(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    note = models.OneToOneField(Note, null=True, on_delete=models.SET_NULL)

    class Meta:
        abstract = True


class ContentBlockBookmark(Bookmark):
    uuid = models.UUIDField(unique=False)
    content_block = models.ForeignKey('books.ContentBlock', on_delete=models.CASCADE)

    class Meta:
        constraints = [
            models.UniqueConstraint(fields=['uuid', 'content_block', 'user'], name='unique_content_bookmark_per_user')
        ]


class ModuleBookmark(Bookmark):
    module = models.ForeignKey('books.Module', on_delete=models.CASCADE)


class ChapterBookmark(Bookmark):
    chapter = models.ForeignKey('books.Chapter', on_delete=models.CASCADE)

class InstrumentBookmark(Bookmark):
    uuid = models.UUIDField(unique=False)
    instrument = models.ForeignKey('basicknowledge.BasicKnowledge', on_delete=models.CASCADE)

    class Meta:
        constraints = [
            models.UniqueConstraint(fields=['uuid', 'instrument', 'user'], name='unique_instrument_bookmark_per_user')
        ]
