# Generated by Django 4.1.8 on 2023-04-11 12:08

import uuid

import django.db.models.deletion
import mptt.fields
import wbcore.contrib.documents.models.documents
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Document",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                (
                    "permission_type",
                    models.CharField(
                        choices=[("INTERNAL", "Internal"), ("PUBLIC", "Public"), ("PRIVATE", "Private")],
                        default="PRIVATE",
                        max_length=8,
                    ),
                ),
                ("name", models.CharField(max_length=255)),
                ("description", models.TextField(blank=True, default="", verbose_name="Description")),
                (
                    "file",
                    models.FileField(
                        max_length=256,
                        upload_to=wbcore.contrib.documents.models.documents.upload_to,
                        verbose_name="File",
                    ),
                ),
                ("system_created", models.BooleanField(default=False, verbose_name="System Created")),
                (
                    "system_key",
                    models.CharField(blank=True, max_length=255, null=True, unique=True, verbose_name="System Key"),
                ),
                ("created", models.DateTimeField(auto_now_add=True, verbose_name="Created")),
                ("updated", models.DateTimeField(auto_now=True, null=True, verbose_name="Updated")),
                (
                    "creator",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="created_%(app_label)s_%(class)s",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Document",
                "verbose_name_plural": "Documents",
                "abstract": False,
                "default_permissions": ("add", "change", "delete", "view", "administrate"),
            },
        ),
        migrations.CreateModel(
            name="ShareableLink",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("valid_until", models.DateTimeField(blank=True, null=True, verbose_name="Valid Until")),
                ("one_time_link", models.BooleanField(default=False, verbose_name="One Time Link")),
                ("manual_invalid", models.BooleanField(default=False)),
                ("uuid", models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                (
                    "document",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="shareable_links",
                        to="documents.document",
                    ),
                ),
            ],
            options={
                "verbose_name": "Shareable Link",
                "verbose_name_plural": "Shareable Links",
            },
        ),
        migrations.CreateModel(
            name="ShareableLinkAccess",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("metadata", models.JSONField(default=dict)),
                ("accessed", models.DateTimeField(auto_now_add=True)),
                (
                    "shareable_link",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="accesses",
                        to="documents.shareablelink",
                    ),
                ),
            ],
            options={
                "verbose_name": "Shareable Link Access",
                "verbose_name_plural": "Shareable Link Accesses",
            },
        ),
        migrations.CreateModel(
            name="DocumentType",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("computed_str", models.CharField(blank=True, max_length=512, null=True, verbose_name="Name")),
                ("name", models.CharField(max_length=255)),
                ("lft", models.PositiveIntegerField(editable=False)),
                ("rght", models.PositiveIntegerField(editable=False)),
                ("tree_id", models.PositiveIntegerField(db_index=True, editable=False)),
                ("level", models.PositiveIntegerField(editable=False)),
                (
                    "parent",
                    mptt.fields.TreeForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="children",
                        to="documents.documenttype",
                        verbose_name="Parent",
                    ),
                ),
            ],
            options={
                "verbose_name": "Document Type",
                "verbose_name_plural": "Document Types",
            },
        ),
        migrations.CreateModel(
            name="DocumentModelRelationship",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("object_id", models.PositiveIntegerField()),
                (
                    "content_type",
                    models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="contenttypes.contenttype"),
                ),
                (
                    "document",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="relationships",
                        to="documents.document",
                    ),
                ),
            ],
            options={
                "verbose_name": "Document Model Relationship",
                "verbose_name_plural": "Document Model Relationships",
            },
        ),
        migrations.AddField(
            model_name="document",
            name="document_type",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="documents",
                to="documents.documenttype",
                verbose_name="Document Type",
            ),
        ),
        migrations.AddIndex(
            model_name="documentmodelrelationship",
            index=models.Index(fields=["content_type", "object_id"], name="documents_d_content_bd3456_idx"),
        ),
    ]
