# Generated by Django 3.1.8 on 2021-04-22 19:40


# Disclaimer
# ----------
#
# Copyright (C) 2021 Helmholtz-Zentrum Hereon
# Copyright (C) 2020-2021 Helmholtz-Zentrum Geesthacht
#
# This file is part of django-academic-community and is released under the
# EUPL-1.2 license.
# See LICENSE in the root of the repository for full licensing details.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the EUROPEAN UNION PUBLIC LICENCE v. 1.2 or later
# as published by the European Commission.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# EUPL-1.2 license for more details.
#
# You should have received a copy of the EUPL-1.2 license along with this
# program. If not, see https://www.eupl.eu/.


import uuid

import django.core.validators
import django.db.models.deletion
import phonenumber_field.modelfields
from django.conf import settings
from django.db import migrations, models

import academic_community.history.models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("activities", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("institutions", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="CommunityAgreement",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "version",
                    models.CharField(
                        help_text="Version of the community agreement",
                        max_length=10,
                        unique=True,
                    ),
                ),
                (
                    "pdf_file",
                    models.FileField(
                        upload_to="static/files/community-agreements/"
                    ),
                ),
            ],
            options={
                "ordering": ["-version"],
            },
        ),
        migrations.CreateModel(
            name="CommunityMember",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "first_name",
                    models.CharField(
                        help_text="First name of the community member.",
                        max_length=50,
                    ),
                ),
                (
                    "last_name",
                    models.CharField(
                        help_text="Last name of the community member.",
                        max_length=255,
                    ),
                ),
                (
                    "reviewed",
                    models.BooleanField(
                        default=False,
                        help_text="This community member has been reviewed by a CLM-community admin.",
                    ),
                ),
                (
                    "title",
                    models.CharField(
                        blank=True,
                        choices=[("DR", "Dr."), ("PROF", "Prof.")],
                        help_text="Academic title of the member.",
                        max_length=5,
                        null=True,
                    ),
                ),
                (
                    "description",
                    models.CharField(
                        blank=True,
                        help_text="More details about the member.",
                        max_length=4000,
                        null=True,
                    ),
                ),
                (
                    "phone_number",
                    phonenumber_field.modelfields.PhoneNumberField(
                        blank=True,
                        help_text="Phone number to contact the member.",
                        max_length=128,
                        null=True,
                        region=None,
                    ),
                ),
                (
                    "is_member",
                    models.BooleanField(
                        default=False,
                        help_text="Whether this person is a community member, or not.",
                    ),
                ),
                (
                    "non_member_details",
                    models.CharField(
                        blank=True,
                        help_text="Further details not related to the CLM-Community membership.",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "start_date",
                    models.DateField(
                        auto_now_add=True,
                        help_text="The date when the member entered the community.",
                        null=True,
                    ),
                ),
                (
                    "end_date",
                    models.DateField(
                        blank=True,
                        help_text="The date when the member left the community.",
                        null=True,
                    ),
                ),
                (
                    "is_cosmo",
                    models.BooleanField(
                        default=False,
                        help_text="Is the member part of COSMO (but not COSMO-CLM)? See also the member category.",
                        verbose_name="COSMO developer",
                    ),
                ),
                (
                    "website",
                    models.URLField(
                        blank=True,
                        help_text="Personal website of the community member.",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "orcid",
                    models.CharField(
                        blank=True,
                        help_text="The ORCID of the community member, see <a href='https://orcid.org/'>orcid.org</a>",
                        max_length=19,
                        null=True,
                        validators=[
                            django.core.validators.RegexValidator(
                                "\\d{4}-\\d{4}-\\d{4}-\\d{3}[\\dX]"
                            )
                        ],
                    ),
                ),
                (
                    "activities",
                    models.ManyToManyField(
                        blank=True, to="activities.Activity"
                    ),
                ),
                (
                    "approved_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="This community member has been approved by this database",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="approver",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": ["last_name", "first_name"],
            },
            bases=(
                academic_community.history.models.RevisionMixin,
                models.Model,
            ),
        ),
        migrations.CreateModel(
            name="MemberCategory",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="The community member category",
                        max_length=50,
                        verbose_name="category name",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Email",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="The UUID to verify the email.",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "email",
                    models.EmailField(
                        help_text="The email address.",
                        max_length=255,
                        unique=True,
                    ),
                ),
                (
                    "is_verified",
                    models.BooleanField(
                        default=False,
                        help_text="Whether the email has been verified or not.",
                    ),
                ),
                (
                    "member",
                    models.ForeignKey(
                        help_text="The community member for this mail.",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="registered_email",
                        to="members.communitymember",
                    ),
                ),
            ],
            bases=(
                academic_community.history.models.RevisionMixin,
                models.Model,
            ),
        ),
        migrations.AddField(
            model_name="communitymember",
            name="category",
            field=models.ForeignKey(
                blank=True,
                help_text="The member category",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                to="members.membercategory",
            ),
        ),
        migrations.AddField(
            model_name="communitymember",
            name="community_agreement",
            field=models.ForeignKey(
                blank=True,
                help_text="The community agreement the member accepted",
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                to="members.communityagreement",
            ),
        ),
        migrations.AddField(
            model_name="communitymember",
            name="email",
            field=models.OneToOneField(
                blank=True,
                help_text="Primary email address of the community member.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="primary_member",
                to="members.email",
            ),
        ),
        migrations.AddField(
            model_name="communitymember",
            name="membership",
            field=models.ManyToManyField(
                through="institutions.AcademicMembership",
                to="institutions.AcademicOrganization",
            ),
        ),
        migrations.AddField(
            model_name="communitymember",
            name="user",
            field=models.OneToOneField(
                blank=True,
                help_text="Associated user account to this profile.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                to=settings.AUTH_USER_MODEL,
            ),
        ),
    ]
