# Generated by Django 5.2.7 on 2026-05-23 15:45

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


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Market",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "uuid",
                    models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("title", models.CharField(max_length=255)),
                ("description", models.TextField(blank=True)),
                (
                    "type",
                    models.CharField(
                        choices=[("yes_no", "Yes/No"), ("multiple", "Multiple Choice")],
                        default="yes_no",
                        max_length=10,
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("open", "Open"),
                            ("closed", "Closed"),
                            ("resolved", "Resolved"),
                        ],
                        default="open",
                        max_length=10,
                    ),
                ),
                ("end_date", models.DateTimeField()),
                (
                    "created_by",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="MarketOption",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "uuid",
                    models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("text", models.CharField(max_length=255)),
                ("position", models.PositiveIntegerField(default=0)),
                (
                    "market",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="options",
                        to="market.market",
                    ),
                ),
            ],
            options={
                "ordering": ["position"],
            },
        ),
        migrations.AddField(
            model_name="market",
            name="winning_option",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="market_won",
                to="market.marketoption",
            ),
        ),
        migrations.CreateModel(
            name="UserBet",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "uuid",
                    models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("amount", models.PositiveIntegerField()),
                (
                    "option",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="user_bets",
                        to="market.marketoption",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="bets",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.AddIndex(
            model_name="marketoption",
            index=models.Index(
                fields=["market", "position"], name="market_mark_market__8679ce_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="marketoption",
            constraint=models.UniqueConstraint(
                fields=("market", "position"), name="unique_market_option_position"
            ),
        ),
        migrations.AddIndex(
            model_name="market",
            index=models.Index(
                fields=["status", "-created_at"], name="market_mark_status_1ef6c3_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="market",
            index=models.Index(
                fields=["end_date"], name="market_mark_end_dat_26bec0_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="userbet",
            index=models.Index(
                fields=["user", "option"], name="market_user_user_id_5e43d9_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="userbet",
            constraint=models.UniqueConstraint(
                fields=("user", "option"), name="unique_user_bet_per_option"
            ),
        ),
    ]
