# Generated by Django 5.2.17 on 2026-09-26 15:52

import django.db.models.deletion
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('organization', '0002_userorganizationassignment'),
    ]

    operations = [
        migrations.CreateModel(
            name='CustomerNumberSequence',
            fields=[
                ('company', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='customer_number_sequence', serialize=False, to='organization.company')),
                ('next_value', models.PositiveBigIntegerField(default=1)),
            ],
            options={
                'constraints': [models.CheckConstraint(condition=models.Q(('next_value__gte', 1)), name='customers_sequence_positive')],
            },
        ),
        migrations.CreateModel(
            name='Customer',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('customer_number', models.CharField(blank=True, editable=False, max_length=22)),
                ('customer_type', models.CharField(choices=[('INDIVIDUAL', 'Individual'), ('ORGANIZATION', 'Organization')], max_length=12)),
                ('full_name', models.CharField(blank=True, max_length=200)),
                ('organization_name', models.CharField(blank=True, max_length=200)),
                ('primary_mobile', models.CharField(blank=True, max_length=32)),
                ('primary_email', models.EmailField(blank=True, max_length=254)),
                ('is_active', models.BooleanField(default=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='customers', to='organization.company')),
            ],
            options={
                'ordering': ['customer_number', 'id'],
                'constraints': [models.UniqueConstraint(fields=('company', 'customer_number'), name='customers_company_number_uniq'), models.CheckConstraint(condition=models.Q(('customer_type__in', ['INDIVIDUAL', 'ORGANIZATION'])), name='customers_type_valid'), models.CheckConstraint(condition=models.Q(('customer_number__regex', '^CUS-[0-9]{8,18}$')), name='customers_number_format'), models.CheckConstraint(condition=models.Q(models.Q(('customer_type', 'INDIVIDUAL'), ('organization_name', ''), models.Q(('full_name', ''), _negated=True)), models.Q(('customer_type', 'ORGANIZATION'), models.Q(('organization_name', ''), _negated=True)), _connector='OR'), name='customers_type_name_valid')],
            },
        ),
    ]
