# Generated by Claude on 2025-12-12

from django.db import migrations


def seed_features(apps, schema_editor):
    """Seed the Feature model with all available features.

    Features are capabilities that can be enabled/disabled or have limits per plan.
    They are assigned to PlanVersions via the PlanFeature M2M relationship.
    """
    Feature = apps.get_model("billing", "Feature")

    features = [
        # =============================================================================
        # Boolean Features (capabilities that can be enabled/disabled)
        # =============================================================================
        {
            "code": "sms_enabled",
            "name": "SMS Messaging",
            "description": "Send SMS notifications and reminders to customers",
            "feature_type": "boolean",
        },
        {
            "code": "masked_calling_enabled",
            "name": "Masked Calling",
            "description": "Make calls with masked caller ID for privacy",
            "feature_type": "boolean",
        },
        {
            "code": "proxy_number_enabled",
            "name": "Proxy Phone Numbers",
            "description": "Use proxy phone numbers for customer communication",
            "feature_type": "boolean",
        },
        {
            "code": "contracts_enabled",
            "name": "Contracts & E-Signatures",
            "description": "Create contracts and collect electronic signatures",
            "feature_type": "boolean",
        },
        {
            "code": "can_use_plugins",
            "name": "Plugin Integrations",
            "description": "Use third-party plugin integrations",
            "feature_type": "boolean",
        },
        {
            "code": "can_use_tasks",
            "name": "Automated Tasks",
            "description": "Create and run automated task workflows",
            "feature_type": "boolean",
        },
        {
            "code": "can_use_analytics",
            "name": "Analytics Dashboard",
            "description": "Access business analytics and reporting",
            "feature_type": "boolean",
        },
        {
            "code": "custom_branding",
            "name": "Custom Branding",
            "description": "Customize branding colors, logo, and styling",
            "feature_type": "boolean",
        },
        {
            "code": "api_access",
            "name": "API Access",
            "description": "Access the public API for integrations",
            "feature_type": "boolean",
        },
        {
            "code": "white_label",
            "name": "White Label",
            "description": "Remove SmoothSchedule branding completely",
            "feature_type": "boolean",
        },
        {
            "code": "priority_support",
            "name": "Priority Support",
            "description": "Get priority customer support response",
            "feature_type": "boolean",
        },
        {
            "code": "sso_enabled",
            "name": "Single Sign-On (SSO)",
            "description": "Enable SSO authentication for team members",
            "feature_type": "boolean",
        },
        {
            "code": "custom_fields",
            "name": "Custom Fields",
            "description": "Create custom data fields for resources and events",
            "feature_type": "boolean",
        },
        {
            "code": "webhooks_enabled",
            "name": "Webhooks",
            "description": "Send webhook notifications for events",
            "feature_type": "boolean",
        },
        {
            "code": "online_payments",
            "name": "Online Payments",
            "description": "Accept online payments from customers",
            "feature_type": "boolean",
        },
        {
            "code": "recurring_appointments",
            "name": "Recurring Appointments",
            "description": "Schedule recurring appointments",
            "feature_type": "boolean",
        },
        {
            "code": "group_bookings",
            "name": "Group Bookings",
            "description": "Allow multiple customers per appointment",
            "feature_type": "boolean",
        },
        {
            "code": "waitlist",
            "name": "Waitlist",
            "description": "Enable waitlist for fully booked slots",
            "feature_type": "boolean",
        },
        {
            "code": "calendar_sync",
            "name": "Calendar Sync",
            "description": "Sync with Google Calendar, Outlook, etc.",
            "feature_type": "boolean",
        },
        {
            "code": "customer_portal",
            "name": "Customer Portal",
            "description": "Branded self-service portal for customers",
            "feature_type": "boolean",
        },
        # =============================================================================
        # Integer Features (limits and quotas)
        # =============================================================================
        {
            "code": "max_users",
            "name": "Maximum Team Members",
            "description": "Maximum number of team member accounts (0 = unlimited)",
            "feature_type": "integer",
        },
        {
            "code": "max_resources",
            "name": "Maximum Resources",
            "description": "Maximum number of resources (staff, rooms, equipment). 0 = unlimited",
            "feature_type": "integer",
        },
        {
            "code": "max_services",
            "name": "Maximum Services",
            "description": "Maximum number of service types. 0 = unlimited",
            "feature_type": "integer",
        },
        {
            "code": "max_appointments_per_month",
            "name": "Monthly Appointment Limit",
            "description": "Maximum appointments per month. 0 = unlimited",
            "feature_type": "integer",
        },
        {
            "code": "max_email_templates",
            "name": "Email Template Limit",
            "description": "Maximum number of custom email templates. 0 = unlimited",
            "feature_type": "integer",
        },
        {
            "code": "max_automated_tasks",
            "name": "Automated Task Limit",
            "description": "Maximum number of automated tasks. 0 = unlimited",
            "feature_type": "integer",
        },
        {
            "code": "max_customers",
            "name": "Customer Limit",
            "description": "Maximum number of customer records. 0 = unlimited",
            "feature_type": "integer",
        },
        {
            "code": "max_locations",
            "name": "Location Limit",
            "description": "Maximum number of business locations. 0 = unlimited",
            "feature_type": "integer",
        },
        {
            "code": "storage_gb",
            "name": "Storage (GB)",
            "description": "File storage limit in gigabytes. 0 = unlimited",
            "feature_type": "integer",
        },
        {
            "code": "max_api_requests_per_day",
            "name": "Daily API Request Limit",
            "description": "Maximum API requests per day. 0 = unlimited",
            "feature_type": "integer",
        },
    ]

    for feature_data in features:
        Feature.objects.update_or_create(
            code=feature_data["code"],
            defaults={
                "name": feature_data["name"],
                "description": feature_data["description"],
                "feature_type": feature_data["feature_type"],
            },
        )


def reverse_seed_features(apps, schema_editor):
    """Remove seeded features."""
    Feature = apps.get_model("billing", "Feature")
    Feature.objects.filter(
        code__in=[
            "sms_enabled",
            "masked_calling_enabled",
            "proxy_number_enabled",
            "contracts_enabled",
            "can_use_plugins",
            "can_use_tasks",
            "can_use_analytics",
            "custom_branding",
            "api_access",
            "white_label",
            "priority_support",
            "sso_enabled",
            "custom_fields",
            "webhooks_enabled",
            "online_payments",
            "recurring_appointments",
            "group_bookings",
            "waitlist",
            "calendar_sync",
            "customer_portal",
            "max_users",
            "max_resources",
            "max_services",
            "max_appointments_per_month",
            "max_email_templates",
            "max_automated_tasks",
            "max_customers",
            "max_locations",
            "storage_gb",
            "max_api_requests_per_day",
        ]
    ).delete()


class Migration(migrations.Migration):

    dependencies = [
        ("billing", "0007_remove_duplicate_feature_fields"),
    ]

    operations = [
        migrations.RunPython(seed_features, reverse_seed_features),
    ]
