# Generated by Django 5.2.6 on 2025-10-18 17:48

from django.db import migrations


def copy_votes_from_site_core(apps, schema_editor):
    """Copy vote data from site_core.Vote to components.Vote"""
    # Try to get the old Vote model - it may not exist in a fresh installation
    try:
        SiteCoreVote = apps.get_model('site_core', 'Vote')
        VotingVote = apps.get_model('components', 'Vote')
        
        # Copy all votes
        for old_vote in SiteCoreVote.objects.all():
            VotingVote.objects.create(
                content_type=old_vote.content_type,
                content_id=old_vote.content_id,
                vote_count=old_vote.vote_count,
                voted_sessions=old_vote.voted_sessions,
                voter_emails=old_vote.voter_emails,
                created_at=old_vote.created_at,
                updated_at=old_vote.updated_at,
            )
    except LookupError:
        # site_core.Vote doesn't exist, skip migration
        pass


def reverse_copy_votes(apps, schema_editor):
    """Reverse migration - not implemented as data would be lost"""
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('components', '0001_initial'),
        ('site_core', '0002_vote_voter_emails_alter_vote_content_type'),
    ]

    operations = [
        migrations.RunPython(copy_votes_from_site_core, reverse_copy_votes),
    ]
