# Generated by Django 4.1.8 on 2023-04-12 12:56

import uuid

import django.core.validators
import django.db.models.deletion
import django_fsm
import wbcore.contrib.directory.models.entries
from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("geography", "0001_initial"),
        ("currency", "0001_initial"),
        ("agenda", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="CompanyType",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("title", models.CharField(max_length=128, unique=True, verbose_name="Title")),
                (
                    "slugify_title",
                    models.CharField(
                        blank=True, max_length=128, null=True, unique=True, verbose_name="Slugified Title"
                    ),
                ),
            ],
            options={
                "verbose_name": "Company Type",
                "verbose_name_plural": "Company Types",
            },
        ),
        migrations.CreateModel(
            name="CustomerStatus",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("title", models.CharField(max_length=32, unique=True, verbose_name="Title")),
                (
                    "slugify_title",
                    models.CharField(
                        blank=True, max_length=32, null=True, unique=True, verbose_name="Slugified Title"
                    ),
                ),
            ],
            options={
                "verbose_name": "Customer Status",
                "verbose_name_plural": "Customer Statuses",
            },
        ),
        migrations.CreateModel(
            name="Entry",
            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")),
                ("is_active", models.BooleanField(default=True)),
                ("deletion_datetime", models.DateTimeField(blank=True, null=True)),
                ("uuid", models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                (
                    "entry_type",
                    models.CharField(
                        choices=[("PERSON", "Person"), ("COMPANY", "Company")],
                        default="",
                        max_length=255,
                        verbose_name="Type",
                    ),
                ),
                (
                    "additional_fields",
                    models.JSONField(blank=True, default=dict, null=True, verbose_name="Additional Fields"),
                ),
                (
                    "activity_heat",
                    models.FloatField(
                        default=0,
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(1),
                        ],
                        verbose_name="Activity Heat",
                    ),
                ),
                (
                    "slugify_computed_str",
                    models.CharField(blank=True, max_length=512, null=True, verbose_name="Slugified Search Name"),
                ),
                (
                    "profile_image",
                    models.ImageField(
                        blank=True,
                        max_length=256,
                        null=True,
                        upload_to=wbcore.contrib.directory.models.entries.upload_to_profile_images,
                    ),
                ),
                (
                    "signature",
                    models.ImageField(
                        blank=True,
                        max_length=256,
                        null=True,
                        upload_to=wbcore.contrib.directory.models.entries.upload_to_signatures,
                    ),
                ),
                ("external_identfier", models.CharField(blank=True, max_length=128, null=True)),
            ],
            options={
                "verbose_name": "Entry",
                "verbose_name_plural": "Entries",
                "ordering": ("entry_type",),
            },
        ),
        migrations.CreateModel(
            name="Position",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("title", models.CharField(max_length=128, unique=True, verbose_name="Title")),
                (
                    "slugify_title",
                    models.CharField(
                        blank=True, max_length=128, null=True, unique=True, verbose_name="Slugified Title"
                    ),
                ),
            ],
            options={
                "verbose_name": "Position",
                "verbose_name_plural": "Positions",
            },
        ),
        migrations.CreateModel(
            name="Specialization",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("title", models.CharField(max_length=128, unique=True, verbose_name="Title")),
                (
                    "slugify_title",
                    models.CharField(
                        blank=True, max_length=128, null=True, unique=True, verbose_name="Slugified Title"
                    ),
                ),
            ],
            options={
                "verbose_name": "Specialization",
                "verbose_name_plural": "Specializations",
            },
        ),
        migrations.CreateModel(
            name="Company",
            fields=[
                (
                    "entry_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="directory.entry",
                    ),
                ),
                ("name", models.CharField(max_length=255, verbose_name="Name")),
                (
                    "headcount",
                    models.CharField(blank=True, default="", max_length=32, verbose_name="Number of employees"),
                ),
                (
                    "tier",
                    models.CharField(
                        blank=True,
                        choices=[("ONE", "1"), ("TWO", "2"), ("THREE", "3"), ("FOUR", "4"), ("FIVE", "5")],
                        max_length=16,
                        null=True,
                        verbose_name="Tier",
                    ),
                ),
                (
                    "asset_allocation",
                    models.CharField(blank=True, default="", max_length=255, verbose_name="Asset Allocation"),
                ),
                (
                    "geographic_focus",
                    models.CharField(blank=True, default="", max_length=255, verbose_name="Geographic Focus"),
                ),
                (
                    "assets_under_management",
                    models.CharField(blank=True, default="", max_length=255, verbose_name="AUM"),
                ),
                (
                    "discretionairy_advisory",
                    models.FloatField(default=0.0, verbose_name="Discretionary Advisory"),
                ),
                ("description", models.TextField(blank=True, default="", verbose_name="Description")),
            ],
            options={
                "verbose_name": "Company",
                "verbose_name_plural": "Companies",
            },
            bases=("directory.entry",),
        ),
        migrations.CreateModel(
            name="Person",
            fields=[
                (
                    "entry_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="directory.entry",
                    ),
                ),
                (
                    "prefix",
                    models.CharField(
                        choices=[
                            ("MR", "Mr."),
                            ("MRS", "Mrs."),
                            ("PROF", "Prof."),
                            ("DR", "Dr."),
                            ("MED", "Med."),
                            ("ME", "Me."),
                        ],
                        max_length=4,
                        verbose_name="Prefix",
                    ),
                ),
                ("first_name", models.CharField(max_length=255, verbose_name="First Name")),
                ("last_name", models.CharField(max_length=255, verbose_name="Last Name")),
                ("initials", models.CharField(blank=True, max_length=4, null=True, verbose_name="Initials")),
                ("active_employee", models.BooleanField(default=True, verbose_name="Available Employee")),
                ("birthday", models.DateField(blank=True, null=True, verbose_name="Birthday")),
                (
                    "personality_profile_red",
                    models.FloatField(
                        default=0,
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(1),
                        ],
                    ),
                ),
                (
                    "personality_profile_green",
                    models.FloatField(
                        default=0,
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(1),
                        ],
                    ),
                ),
                (
                    "personality_profile_blue",
                    models.FloatField(
                        default=0,
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(1),
                        ],
                    ),
                ),
                ("formal", models.BooleanField(default=True, verbose_name="Formal")),
            ],
            options={
                "verbose_name": "Person",
                "verbose_name_plural": "Persons",
            },
            bases=("directory.entry",),
        ),
        migrations.CreateModel(
            name="WebsiteContact",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("primary", models.BooleanField(default=False, verbose_name="Primary")),
                (
                    "location",
                    models.CharField(
                        choices=[
                            ("WORK", "Work"),
                            ("PRIVATE", "Private"),
                            ("HOME", "Home"),
                            ("OTHER", "Other"),
                        ],
                        default="WORK",
                        max_length=32,
                        verbose_name="Location",
                    ),
                ),
                ("url", models.URLField(verbose_name="URL")),
                (
                    "entry",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="websites",
                        to="directory.entry",
                        verbose_name="Entry",
                    ),
                ),
            ],
            options={
                "verbose_name": "Website Contact",
                "verbose_name_plural": "Website Contacts",
            },
        ),
        migrations.CreateModel(
            name="TelephoneContact",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("primary", models.BooleanField(default=False, verbose_name="Primary")),
                (
                    "location",
                    models.CharField(
                        choices=[
                            ("WORK", "Work"),
                            ("PRIVATE", "Private"),
                            ("HOME", "Home"),
                            ("OTHER", "Other"),
                        ],
                        default="WORK",
                        max_length=32,
                        verbose_name="Location",
                    ),
                ),
                ("number", models.CharField(max_length=255, verbose_name="Number")),
                (
                    "telephone_type",
                    models.CharField(
                        choices=[("FIX", "Fix"), ("CELL", "Cell"), ("FAX", "Fax"), ("OTHER", "Other")],
                        default="FIX",
                        max_length=32,
                        verbose_name="Type",
                    ),
                ),
                (
                    "entry",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="telephones",
                        to="directory.entry",
                        verbose_name="Entry",
                    ),
                ),
            ],
            options={
                "verbose_name": "Telephone Contact",
                "verbose_name_plural": "Telephone Contacts",
            },
        ),
        migrations.CreateModel(
            name="SocialMediaContact",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("primary", models.BooleanField(default=False, verbose_name="Primary")),
                (
                    "location",
                    models.CharField(
                        choices=[
                            ("WORK", "Work"),
                            ("PRIVATE", "Private"),
                            ("HOME", "Home"),
                            ("OTHER", "Other"),
                        ],
                        default="WORK",
                        max_length=32,
                        verbose_name="Location",
                    ),
                ),
                (
                    "platform",
                    models.CharField(
                        choices=[
                            ("FACEBOOK", "Facebook"),
                            ("INSTAGRAM", "Instagram"),
                            ("LINKEDIN", "LinkedIn"),
                            ("REDDIT", "Reddit"),
                            ("TIKTOK", "TikTok"),
                            ("TUMBLR", "Tumblr"),
                            ("TWITTER", "Twitter"),
                            ("XING", "Xing"),
                        ],
                        help_text="The social media platform for this contact",
                        max_length=32,
                        verbose_name="Platform",
                    ),
                ),
                ("url", models.URLField(verbose_name="URL")),
                (
                    "entry",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="social_media",
                        to="directory.entry",
                        verbose_name="Entry",
                    ),
                ),
            ],
            options={
                "verbose_name": "Social Media Contact",
                "verbose_name_plural": "Social Media Contacts",
            },
        ),
        migrations.CreateModel(
            name="RelationshipType",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("title", models.CharField(max_length=256, unique=True, verbose_name="Relationship Type")),
                (
                    "slugify_title",
                    models.CharField(
                        blank=True, max_length=256, null=True, unique=True, verbose_name="Slugified Title"
                    ),
                ),
                (
                    "counter_relationship",
                    models.OneToOneField(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="reverse_counter_relationship",
                        to="directory.relationshiptype",
                        verbose_name="Counter Relationship",
                    ),
                ),
            ],
            options={
                "verbose_name": "Relationship Type",
                "verbose_name_plural": "Relationship Types",
            },
        ),
        migrations.CreateModel(
            name="Relationship",
            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")),
                (
                    "from_entry",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="from_entry",
                        to="directory.entry",
                        verbose_name="Relationship From",
                    ),
                ),
                (
                    "relationship_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        to="directory.relationshiptype",
                        verbose_name="Type",
                    ),
                ),
                (
                    "to_entry",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="to_entry",
                        to="directory.entry",
                        verbose_name="Relationship To",
                    ),
                ),
            ],
            options={
                "verbose_name": "Relationship",
                "verbose_name_plural": "Relationships",
            },
        ),
        migrations.AddField(
            model_name="entry",
            name="relationships",
            field=models.ManyToManyField(
                blank=True,
                through="directory.Relationship",
                to="directory.entry",
                verbose_name="The Entry's Relationships",
            ),
        ),
        migrations.CreateModel(
            name="EmployerEmployeeRelationship",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("primary", models.BooleanField(default=False, verbose_name="Primary")),
                (
                    "position",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="position_of_employee",
                        to="directory.position",
                        verbose_name="Position",
                    ),
                ),
            ],
            options={
                "verbose_name": "Employer Employee Relationship",
            },
        ),
        migrations.CreateModel(
            name="EmailContact",
            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")),
                ("primary", models.BooleanField(default=False, verbose_name="Primary")),
                (
                    "location",
                    models.CharField(
                        choices=[
                            ("WORK", "Work"),
                            ("PRIVATE", "Private"),
                            ("HOME", "Home"),
                            ("OTHER", "Other"),
                        ],
                        default="WORK",
                        max_length=32,
                        verbose_name="Location",
                    ),
                ),
                ("address", models.EmailField(max_length=254, verbose_name="Email Address")),
                (
                    "entry",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="emails",
                        to="directory.entry",
                        verbose_name="Entry",
                    ),
                ),
            ],
            options={
                "verbose_name": "E-Mail Contact",
                "verbose_name_plural": "E-Mail Contacts",
            },
        ),
        migrations.CreateModel(
            name="ClientManagerRelationship",
            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")),
                ("primary", models.BooleanField(default=False, verbose_name="Primary")),
                (
                    "status",
                    django_fsm.FSMField(
                        choices=[
                            ("DRAFT", "Draft"),
                            ("PENDINGADD", "Pending Add"),
                            ("PENDINGREMOVE", "Pending Remove"),
                            ("APPROVED", "Approved"),
                            ("REMOVED", "Removed"),
                        ],
                        default="DRAFT",
                        max_length=50,
                        verbose_name="Status",
                    ),
                ),
                ("created", models.DateTimeField(auto_now_add=True, verbose_name="Created")),
                (
                    "client",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="client_of",
                        to="directory.entry",
                        verbose_name="Client",
                    ),
                ),
            ],
            options={
                "verbose_name": "Client Manager Relationship",
                "verbose_name_plural": "Client Manager Relationships",
            },
        ),
        migrations.CreateModel(
            name="BankingContact",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                (
                    "status",
                    django_fsm.FSMField(
                        choices=[("DRAFT", "Draft"), ("PENDING", "Pending"), ("APPROVED", "Approved")],
                        default="DRAFT",
                        max_length=50,
                        verbose_name="Status",
                    ),
                ),
                ("primary", models.BooleanField(default=False, verbose_name="Primary")),
                (
                    "location",
                    models.CharField(
                        choices=[
                            ("WORK", "Work"),
                            ("PRIVATE", "Private"),
                            ("HOME", "Home"),
                            ("OTHER", "Other"),
                        ],
                        default="WORK",
                        max_length=32,
                        verbose_name="Location",
                    ),
                ),
                ("institute", models.CharField(max_length=255, verbose_name="Institute")),
                (
                    "institute_additional",
                    models.CharField(blank=True, max_length=255, null=True, verbose_name="Institute (Additional)"),
                ),
                ("iban", models.CharField(blank=True, max_length=38, null=True, verbose_name="IBAN")),
                (
                    "swift_bic",
                    models.CharField(blank=True, max_length=11, null=True, verbose_name="SWIFT/BIC"),
                ),
                ("edited", models.DateTimeField(auto_now=True, verbose_name="Edited")),
                (
                    "additional_information",
                    models.TextField(
                        blank=True,
                        help_text="Can be used in place of IBAN to communicate banking information",
                        null=True,
                        verbose_name="Additional Information",
                    ),
                ),
                (
                    "currency",
                    models.ForeignKey(
                        blank=True,
                        db_column="linked_currency",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="currency.currency",
                        verbose_name="Currency",
                    ),
                ),
                (
                    "entry",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="banking",
                        to="directory.entry",
                        verbose_name="Entry",
                    ),
                ),
            ],
            options={
                "verbose_name": "Banking Contact",
                "verbose_name_plural": "Banking Contacts",
                "permissions": (("can_approve_bankingcontact", "Can approve Banking Contact"),),
            },
        ),
        migrations.CreateModel(
            name="AddressContact",
            fields=[
                (
                    "id",
                    models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("primary", models.BooleanField(default=False, verbose_name="Primary")),
                (
                    "location",
                    models.CharField(
                        choices=[
                            ("WORK", "Work"),
                            ("PRIVATE", "Private"),
                            ("HOME", "Home"),
                            ("OTHER", "Other"),
                        ],
                        default="WORK",
                        max_length=32,
                        verbose_name="Location",
                    ),
                ),
                ("street", models.CharField(blank=True, max_length=255, null=True, verbose_name="Street")),
                (
                    "street_additional",
                    models.CharField(blank=True, max_length=255, null=True, verbose_name="Street (Additional)"),
                ),
                ("zip", models.CharField(blank=True, max_length=255, null=True, verbose_name="ZIP")),
                ("city", models.CharField(blank=True, max_length=255, null=True, verbose_name="City")),
                ("province", models.CharField(blank=True, max_length=255, null=True, verbose_name="Province")),
                (
                    "entry",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="addresses",
                        to="directory.entry",
                        verbose_name="Entry",
                    ),
                ),
                (
                    "geography_city",
                    models.ForeignKey(
                        blank=True,
                        limit_choices_to={"level": 3},
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="contact_city",
                        to="geography.geography",
                        verbose_name="City",
                    ),
                ),
            ],
            options={
                "verbose_name": "Address Contact",
                "verbose_name_plural": "Address Contacts",
            },
        ),
        migrations.AddConstraint(
            model_name="websitecontact",
            constraint=models.UniqueConstraint(fields=("url", "entry"), name="unique_website_entry"),
        ),
        migrations.AddConstraint(
            model_name="telephonecontact",
            constraint=models.UniqueConstraint(fields=("number", "entry"), name="unique_number_entry"),
        ),
        migrations.AddConstraint(
            model_name="socialmediacontact",
            constraint=models.UniqueConstraint(fields=("url", "entry"), name="unique_social_entry"),
        ),
        migrations.AddField(
            model_name="person",
            name="employers",
            field=models.ManyToManyField(
                blank=True,
                help_text="The person's employers",
                related_name="employees",
                through="directory.EmployerEmployeeRelationship",
                to="directory.company",
                verbose_name="Employers",
            ),
        ),
        migrations.AddField(
            model_name="person",
            name="specializations",
            field=models.ManyToManyField(blank=True, to="directory.specialization", verbose_name="Specializations"),
        ),
        migrations.AddField(
            model_name="entry",
            name="relationship_managers",
            field=models.ManyToManyField(
                blank=True,
                help_text="People in charge of this entry",
                related_name="clients",
                through="directory.ClientManagerRelationship",
                to="directory.person",
                verbose_name="Relationship Managers",
            ),
        ),
        migrations.AddField(
            model_name="employeremployeerelationship",
            name="employee",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="employer",
                to="directory.person",
                verbose_name="Employee",
            ),
        ),
        migrations.AddField(
            model_name="employeremployeerelationship",
            name="employer",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="employee",
                to="directory.company",
                verbose_name="Employer",
            ),
        ),
        migrations.AddConstraint(
            model_name="emailcontact",
            constraint=models.UniqueConstraint(fields=("entry", "address"), name="entry_address_unique_together"),
        ),
        migrations.AddField(
            model_name="company",
            name="customer_status",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="company",
                to="directory.customerstatus",
                verbose_name="Customer Status",
            ),
        ),
        migrations.AddField(
            model_name="company",
            name="type",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="company",
                to="directory.companytype",
                verbose_name="Type",
            ),
        ),
        migrations.AddField(
            model_name="clientmanagerrelationship",
            name="relationship_manager",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="manager_of",
                to="directory.person",
                verbose_name="Relationship Manager",
            ),
        ),
        migrations.AddConstraint(
            model_name="bankingcontact",
            constraint=models.UniqueConstraint(fields=("iban", "entry"), name="unique_iban_entry"),
        ),
        migrations.AddConstraint(
            model_name="employeremployeerelationship",
            constraint=models.UniqueConstraint(fields=("employee", "employer"), name="unique_employeremployee"),
        ),
    ]
