# Generated by Django 5.2.8 on 2025-12-04 19:15

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('schedule', '0027_add_deposit_percent_back'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='ContractTemplate',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
                ('content', models.TextField(help_text='Contract body with {{VARIABLE}} placeholders')),
                ('scope', models.CharField(choices=[('CUSTOMER', 'Customer-Level'), ('APPOINTMENT', 'Appointment-Level')], default='APPOINTMENT', max_length=20)),
                ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('ACTIVE', 'Active'), ('ARCHIVED', 'Archived')], default='DRAFT', max_length=20)),
                ('expires_after_days', models.PositiveIntegerField(blank=True, help_text='Days after sending before contract expires (null=never)', null=True)),
                ('version', models.PositiveIntegerField(default=1)),
                ('version_notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_contract_templates', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Contract',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('template_version', models.PositiveIntegerField(help_text='Version of template when contract was created')),
                ('title', models.CharField(max_length=200)),
                ('content_html', models.TextField(help_text='Rendered HTML content at time of creation')),
                ('content_hash', models.CharField(help_text='SHA-256 hash of content for tamper detection', max_length=64)),
                ('status', models.CharField(choices=[('PENDING', 'Pending Signature'), ('SIGNED', 'Signed'), ('EXPIRED', 'Expired'), ('VOIDED', 'Voided')], default='PENDING', max_length=20)),
                ('signing_token', models.CharField(help_text='Token for public signing URL', max_length=64, unique=True)),
                ('expires_at', models.DateTimeField(blank=True, null=True)),
                ('sent_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('pdf_path', models.CharField(blank=True, max_length=500)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contracts', to=settings.AUTH_USER_MODEL)),
                ('event', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contracts', to='schedule.event')),
                ('sent_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sent_contracts', to=settings.AUTH_USER_MODEL)),
                ('template', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contracts', to='contracts.contracttemplate')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ServiceContractRequirement',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('display_order', models.PositiveIntegerField(default=0)),
                ('is_required', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('service', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contract_requirements', to='schedule.service')),
                ('template', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='service_requirements', to='contracts.contracttemplate')),
            ],
            options={
                'ordering': ['display_order'],
            },
        ),
        migrations.CreateModel(
            name='ContractSignature',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('consent_checkbox_checked', models.BooleanField(default=False)),
                ('consent_text', models.TextField(help_text='Exact consent language shown to signer')),
                ('electronic_consent_given', models.BooleanField(default=False)),
                ('electronic_consent_text', models.TextField(help_text='ESIGN Act consent text')),
                ('signer_name', models.CharField(max_length=200)),
                ('signer_email', models.EmailField(max_length=254)),
                ('signed_at', models.DateTimeField()),
                ('ip_address', models.GenericIPAddressField()),
                ('user_agent', models.TextField()),
                ('browser_fingerprint', models.CharField(blank=True, max_length=64)),
                ('document_hash_at_signing', models.CharField(help_text='SHA-256 hash of contract content at moment of signing', max_length=64)),
                ('latitude', models.DecimalField(blank=True, decimal_places=6, max_digits=9, null=True)),
                ('longitude', models.DecimalField(blank=True, decimal_places=6, max_digits=9, null=True)),
                ('contract', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='signature', to='contracts.contract')),
            ],
            options={
                'indexes': [models.Index(fields=['signed_at'], name='contracts_c_signed__e562eb_idx')],
            },
        ),
        migrations.AddIndex(
            model_name='contract',
            index=models.Index(fields=['signing_token'], name='contracts_c_signing_4e91ca_idx'),
        ),
        migrations.AddIndex(
            model_name='contract',
            index=models.Index(fields=['customer', 'status'], name='contracts_c_custome_791003_idx'),
        ),
        migrations.AddIndex(
            model_name='contract',
            index=models.Index(fields=['template', 'customer'], name='contracts_c_templat_e832ba_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='servicecontractrequirement',
            unique_together={('service', 'template')},
        ),
    ]
