# Generated by Django 5.2.8 on 2025-12-12 19:54

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


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0027_remove_legacy_feature_fields'),
        ('schedule', '0036_add_service_buffer_and_notification_fields'),
    ]

    operations = [
        migrations.AddField(
            model_name='resource',
            name='is_mobile',
            field=models.BooleanField(default=False, help_text='If True, resource can work across locations (e.g., plumber, mobile mechanic)'),
        ),
        migrations.AddField(
            model_name='service',
            name='is_global',
            field=models.BooleanField(default=True, help_text='If True, service available at all locations. If False, use locations M2M.'),
        ),
        migrations.AddField(
            model_name='timeblock',
            name='is_business_wide',
            field=models.BooleanField(default=False, help_text='If True, this block applies to ALL locations and resources'),
        ),
        migrations.AlterField(
            model_name='timeblock',
            name='resource',
            field=models.ForeignKey(blank=True, help_text='Specific resource (null = location-level or business-wide block)', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='time_blocks', to='schedule.resource'),
        ),
        migrations.CreateModel(
            name='Location',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('address_line1', models.CharField(blank=True, max_length=255)),
                ('address_line2', models.CharField(blank=True, max_length=255)),
                ('city', models.CharField(blank=True, max_length=100)),
                ('state', models.CharField(blank=True, max_length=100)),
                ('postal_code', models.CharField(blank=True, max_length=20)),
                ('country', models.CharField(default='US', max_length=100)),
                ('phone', models.CharField(blank=True, max_length=20)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('timezone', models.CharField(blank=True, max_length=50)),
                ('is_active', models.BooleanField(default=True)),
                ('is_primary', models.BooleanField(default=False)),
                ('display_order', models.PositiveIntegerField(default=0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('business', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='locations', to='core.tenant')),
            ],
            options={
                'ordering': ['display_order', 'name'],
            },
        ),
        migrations.AddField(
            model_name='event',
            name='location',
            field=models.ForeignKey(blank=True, help_text='Location where event takes place', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='events', to='schedule.location'),
        ),
        migrations.AddField(
            model_name='resource',
            name='location',
            field=models.ForeignKey(blank=True, help_text='Fixed location (null if mobile resource)', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resources', to='schedule.location'),
        ),
        migrations.AddField(
            model_name='service',
            name='locations',
            field=models.ManyToManyField(blank=True, help_text='Locations where this service is offered (only used if is_global=False)', related_name='services', to='schedule.location'),
        ),
        migrations.AddField(
            model_name='timeblock',
            name='location',
            field=models.ForeignKey(blank=True, help_text='Specific location (null = use resource location or business-wide)', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='time_blocks', to='schedule.location'),
        ),
        migrations.AddIndex(
            model_name='location',
            index=models.Index(fields=['business', 'is_active'], name='schedule_lo_busines_77134d_idx'),
        ),
        migrations.AddIndex(
            model_name='location',
            index=models.Index(fields=['business', 'display_order'], name='schedule_lo_busines_3ba4d7_idx'),
        ),
        migrations.AddConstraint(
            model_name='location',
            constraint=models.UniqueConstraint(condition=models.Q(('is_primary', True)), fields=('business',), name='unique_primary_location_per_business'),
        ),
    ]
