# Generated by Django 5.1.8 on 2025-05-04 10:14

import access.fields
import access.models.tenancy
import core.lib.slash_commands
import core.models.ticket_base
import core.models.ticket_comment_base
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('access', '0005_entity_person_entityhistory_entitynotes_role_and_more'),
        ('core', '0021_alter_ticketlinkeditem_item_type'),
        ('project_management', '0005_projecthistory_projectmilestonehistory_and_more'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='TicketCommentBase',
            fields=[
                ('id', models.AutoField(help_text='Comment ID Number', primary_key=True, serialize=False, unique=True, verbose_name='Number')),
                ('external_ref', models.IntegerField(blank=True, default=None, help_text='External System reference', null=True, verbose_name='Reference Number')),
                ('external_system', models.IntegerField(blank=True, choices=[(1, 'Github'), (2, 'Gitlab'), (9999, 'Custom #1 (Imported)'), (9998, 'Custom #2 (Imported)'), (9997, 'Custom #3 (Imported)'), (9996, 'Custom #4 (Imported)'), (9995, 'Custom #5 (Imported)'), (9994, 'Custom #6 (Imported)'), (9993, 'Custom #7 (Imported)'), (9992, 'Custom #8 (Imported)'), (9991, 'Custom #9 (Imported)')], default=None, help_text='External system this item derives', null=True, verbose_name='External System')),
                ('comment_type', models.CharField(choices=core.models.ticket_comment_base.TicketCommentBase.get_comment_type_choices, help_text='Type this comment is. derived from Meta.verbose_name', max_length=30, verbose_name='Type')),
                ('body', models.TextField(blank=True, help_text='Comment contents', null=True, verbose_name='Comment')),
                ('private', models.BooleanField(default=False, help_text='Is this comment private', verbose_name='Private')),
                ('duration', models.IntegerField(default=0, help_text='Time spent in seconds', verbose_name='Duration')),
                ('estimation', models.IntegerField(default=0, help_text='Time estimation in seconds', verbose_name='Estimate')),
                ('is_template', models.BooleanField(default=False, help_text='Is this comment a template', verbose_name='Template')),
                ('source', models.IntegerField(choices=[(1, 'Direct'), (2, 'E-Mail'), (3, 'Helpdesk'), (4, 'Phone'), (5, 'Service Catalog'), (6, 'SMS Message')], default=3, help_text='Origin type for this comment', verbose_name='Source')),
                ('is_closed', models.BooleanField(default=False, help_text='Is this comment considered Closed?', verbose_name='Comment Closed')),
                ('date_closed', models.DateTimeField(blank=True, help_text='Date ticket closed', null=True, verbose_name='Closed Date')),
                ('created', access.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, help_text='Date and time of creation', verbose_name='Created')),
                ('modified', access.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, help_text='Date and time of last modification', verbose_name='Modified')),
                ('category', models.ForeignKey(blank=True, default=None, help_text='Category of the comment', null=True, on_delete=django.db.models.deletion.PROTECT, to='core.ticketcommentcategory', verbose_name='Category')),
                ('organization', models.ForeignKey(help_text='Organization this belongs to', on_delete=django.db.models.deletion.CASCADE, related_name='+', to='access.organization', validators=[access.models.tenancy.TenancyObject.validatate_organization_exists], verbose_name='Organization')),
                ('parent', models.ForeignKey(blank=True, default=None, help_text='Parent ID for creating discussion threads', null=True, on_delete=django.db.models.deletion.PROTECT, to='core.ticketcommentbase', verbose_name='Parent Comment')),
                ('template', models.ForeignKey(blank=True, default=None, help_text='Comment Template to use', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='comment_template', to='core.ticketcommentbase', verbose_name='Template')),
            ],
            options={
                'verbose_name': 'Ticket Comment',
                'verbose_name_plural': 'Ticket Comments',
                'ordering': ['id'],
                'permissions': [('import_ticketcommentbase', 'Can import ticket comment.'), ('purge_ticketcommentbase', 'Can purge ticket comment.'), ('triage_ticketcommentbase', 'Can triage ticket comment.')],
                'sub_model_type': 'comment',
            },
            bases=(core.lib.slash_commands.SlashCommands, models.Model),
        ),
        migrations.CreateModel(
            name='TicketBase',
            fields=[
                ('id', models.AutoField(help_text='Ticket ID Number', primary_key=True, serialize=False, unique=True, verbose_name='Number')),
                ('external_system', models.IntegerField(blank=True, choices=[(1, 'Github'), (2, 'Gitlab'), (9999, 'Custom #1 (Imported)'), (9998, 'Custom #2 (Imported)'), (9997, 'Custom #3 (Imported)'), (9996, 'Custom #4 (Imported)'), (9995, 'Custom #5 (Imported)'), (9994, 'Custom #6 (Imported)'), (9993, 'Custom #7 (Imported)'), (9992, 'Custom #8 (Imported)'), (9991, 'Custom #9 (Imported)')], default=None, help_text='External system this item derives', null=True, verbose_name='External System')),
                ('external_ref', models.IntegerField(blank=True, default=None, help_text='External System reference', null=True, verbose_name='Reference Number')),
                ('ticket_type', models.CharField(blank=True, choices=core.models.ticket_base.TicketBase.get_ticket_type_choices, default='ticket', help_text='Ticket Type. (derived from ticket model)', max_length=30, validators=[core.models.ticket_base.TicketBase.validate_not_null], verbose_name='Ticket Type')),
                ('status', models.IntegerField(choices=[(1, 'Draft'), (2, 'New'), (3, 'Assigned'), (6, 'Assigned (Planning)'), (7, 'Pending'), (8, 'Solved'), (4, 'Closed'), (5, 'Invalid')], default=2, help_text='Status of ticket', verbose_name='Status')),
                ('title', models.CharField(help_text='Title of the Ticket', max_length=150, unique=True, verbose_name='Title')),
                ('description', models.TextField(blank=True, help_text='Description for the ticket.', null=True, verbose_name='Description')),
                ('private', models.BooleanField(default=False, help_text='Is this ticket private', verbose_name='Private')),
                ('urgency', models.IntegerField(blank=True, choices=[(1, 'Very Low'), (2, 'Low'), (3, 'Medium'), (4, 'High'), (5, 'Very High')], default=1, help_text='How urgent is this tickets resolution for the user?', null=True, verbose_name='Urgency')),
                ('impact', models.IntegerField(blank=True, choices=[(1, 'Very Low'), (2, 'Low'), (3, 'Medium'), (4, 'High'), (5, 'Very High')], default=1, help_text='End user assessed impact', null=True, verbose_name='Impact')),
                ('priority', models.IntegerField(blank=True, choices=[(1, 'Very Low'), (2, 'Low'), (3, 'Medium'), (4, 'High'), (5, 'Very High'), (6, 'Major')], default=1, help_text='What priority should this ticket for its completion', null=True, verbose_name='Priority')),
                ('planned_start_date', models.DateTimeField(blank=True, help_text='Planned start date.', null=True, verbose_name='Planned Start Date')),
                ('planned_finish_date', models.DateTimeField(blank=True, help_text='Planned finish date', null=True, verbose_name='Planned Finish Date')),
                ('real_start_date', models.DateTimeField(blank=True, help_text='Real start date', null=True, verbose_name='Real Start Date')),
                ('real_finish_date', models.DateTimeField(blank=True, help_text='Real finish date', null=True, verbose_name='Real Finish Date')),
                ('is_deleted', models.BooleanField(blank=True, default=False, help_text='Is the ticket deleted? And ready to be purged', verbose_name='Deleted')),
                ('is_solved', models.BooleanField(blank=True, default=False, help_text='Is this ticket solved?', verbose_name='Solved')),
                ('date_solved', models.DateTimeField(blank=True, help_text='Date ticket solved', null=True, verbose_name='Solved Date')),
                ('is_closed', models.BooleanField(blank=True, default=False, help_text='Is this ticket closed?', verbose_name='Closed')),
                ('date_closed', models.DateTimeField(blank=True, help_text='Date ticket closed', null=True, verbose_name='Closed Date')),
                ('created', access.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, help_text='Date and time of creation', verbose_name='Created')),
                ('modified', access.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, help_text='Date and time of last modification', verbose_name='Modified')),
                ('assigned_to', models.ManyToManyField(blank=True, help_text='Users / Groups assigned to the ticket', related_name='ticket_assigned', to='access.entity', verbose_name='Users / Groups Assigned')),
                ('category', models.ForeignKey(blank=True, help_text='Category for this ticket', null=True, on_delete=django.db.models.deletion.PROTECT, to='core.ticketcategory', verbose_name='Category')),
                ('milestone', models.ForeignKey(blank=True, help_text='Assign to a milestone', null=True, on_delete=django.db.models.deletion.PROTECT, to='project_management.projectmilestone', verbose_name='Project Milestone')),
                ('opened_by', models.ForeignKey(help_text='Who is the ticket for', on_delete=django.db.models.deletion.PROTECT, related_name='ticket_opened', to=settings.AUTH_USER_MODEL, verbose_name='Opened By')),
                ('organization', models.ForeignKey(help_text='Organization this belongs to', on_delete=django.db.models.deletion.CASCADE, related_name='+', to='access.organization', validators=[access.models.tenancy.TenancyObject.validatate_organization_exists], verbose_name='Organization')),
                ('parent_ticket', models.ForeignKey(blank=True, help_text='Parent of this ticket', null=True, on_delete=django.db.models.deletion.PROTECT, to='core.ticketbase', verbose_name='Parent Ticket')),
                ('project', models.ForeignKey(blank=True, help_text='Assign to a project', null=True, on_delete=django.db.models.deletion.PROTECT, to='project_management.project', verbose_name='Project')),
                ('subscribed_to', models.ManyToManyField(blank=True, help_text='Users / Groups subscribed to the ticket', related_name='ticket_subscription', to='access.entity', verbose_name='Users / Groups Subscribed')),
            ],
            options={
                'verbose_name': 'Ticket',
                'verbose_name_plural': 'Tickets',
                'ordering': ['id'],
                'sub_model_type': 'ticket',
                'unique_together': {('external_system', 'external_ref')},
            },
            bases=(core.lib.slash_commands.SlashCommands, models.Model),
        ),
        migrations.CreateModel(
            name='TicketCommentSolution',
            fields=[
                ('ticketcommentbase_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.ticketcommentbase')),
            ],
            options={
                'verbose_name': 'Ticket Comment Solution',
                'verbose_name_plural': 'Ticket Comment Solutions',
                'ordering': ['id'],
                'permissions': [('import_ticketcommentsolution', 'Can import ticket solution comment.'), ('purge_ticketcommentsolution', 'Can purge ticket solution comment.'), ('triage_ticketcommentsolution', 'Can triage ticket solution comment.')],
                'sub_model_type': 'solution',
            },
            bases=('core.ticketcommentbase',),
        ),
        migrations.AddField(
            model_name='ticketcommentbase',
            name='ticket',
            field=models.ForeignKey(help_text='Ticket this comment belongs to', on_delete=django.db.models.deletion.PROTECT, to='core.ticketbase', verbose_name='Ticket'),
        ),
        migrations.AddField(
            model_name='ticketcommentbase',
            name='user',
            field=models.ForeignKey(help_text='Who made the comment', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='comment_user', to='access.entity', verbose_name='User'),
        ),
        migrations.AlterUniqueTogether(
            name='ticketcommentbase',
            unique_together={('external_system', 'external_ref')},
        ),
    ]
