# Generated by Django 3.1.3 on 2021-01-05 11:03

import agir.payments.model_fields
import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import django_countries.fields
import django_prometheus.models
import phonenumber_field.modelfields


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("people", "0001_creer_modeles"),
    ]

    operations = [
        migrations.CreateModel(
            name="Subscription",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "created",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        editable=False,
                        verbose_name="date de création",
                    ),
                ),
                (
                    "modified",
                    models.DateTimeField(
                        auto_now=True, verbose_name="dernière modification"
                    ),
                ),
                (
                    "day_of_month",
                    models.PositiveSmallIntegerField(
                        blank=True,
                        editable=False,
                        null=True,
                        verbose_name="Jour du mois",
                    ),
                ),
                (
                    "price",
                    models.IntegerField(
                        editable=False, verbose_name="prix en centimes d'euros"
                    ),
                ),
                ("type", models.CharField(max_length=255, verbose_name="Type")),
                (
                    "mode",
                    models.CharField(max_length=70, verbose_name="Mode de paiement"),
                ),
                (
                    "status",
                    models.IntegerField(
                        choices=[
                            (
                                0,
                                "Souscription en attente de confirmation par SystemPay",
                            ),
                            (1, "Souscription active"),
                            (
                                2,
                                "Souscription abandonnée avant complétion par la personne",
                            ),
                            (3, "Souscription refusée côté FI"),
                            (4, "Souscription refusée côté banque"),
                            (5, "Souscription terminée"),
                        ],
                        default=0,
                        verbose_name="status",
                    ),
                ),
                ("meta", models.JSONField(blank=True, default=dict)),
                (
                    "end_date",
                    models.DateField(
                        blank=True, null=True, verbose_name="Fin de l'abonnement"
                    ),
                ),
                (
                    "person",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="subscriptions",
                        to="people.person",
                    ),
                ),
            ],
            options={
                "verbose_name": "Paiement récurrent",
                "verbose_name_plural": "Paiements récurrents",
            },
        ),
        migrations.CreateModel(
            name="Payment",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "created",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        editable=False,
                        verbose_name="date de création",
                    ),
                ),
                (
                    "modified",
                    models.DateTimeField(
                        auto_now=True, verbose_name="dernière modification"
                    ),
                ),
                (
                    "coordinates",
                    django.contrib.gis.db.models.fields.PointField(
                        blank=True,
                        geography=True,
                        null=True,
                        srid=4326,
                        verbose_name="coordonnées",
                    ),
                ),
                (
                    "coordinates_type",
                    models.PositiveSmallIntegerField(
                        choices=[
                            (0, "Coordonnées manuelles"),
                            (10, "Coordonnées automatiques précises"),
                            (
                                20,
                                "Coordonnées automatiques approximatives (niveau rue)",
                            ),
                            (
                                25,
                                "Coordonnées automatique approximatives (arrondissement)",
                            ),
                            (30, "Coordonnées automatiques approximatives (ville)"),
                            (50, "Coordonnées automatiques (qualité inconnue)"),
                            (254, "Pas de position géographique"),
                            (255, "Coordonnées introuvables"),
                        ],
                        editable=False,
                        help_text="Comment les coordonnées ci-dessus ont-elle été acquises",
                        null=True,
                        verbose_name="type de coordonnées",
                    ),
                ),
                (
                    "location_name",
                    models.CharField(
                        blank=True, max_length=255, verbose_name="nom du lieu"
                    ),
                ),
                (
                    "location_address1",
                    models.CharField(
                        blank=True, max_length=100, verbose_name="adresse (1ère ligne)"
                    ),
                ),
                (
                    "location_address2",
                    models.CharField(
                        blank=True, max_length=100, verbose_name="adresse (2ème ligne)"
                    ),
                ),
                (
                    "location_citycode",
                    models.CharField(
                        blank=True, max_length=20, verbose_name="code INSEE"
                    ),
                ),
                (
                    "location_city",
                    models.CharField(blank=True, max_length=100, verbose_name="ville"),
                ),
                (
                    "location_zip",
                    models.CharField(
                        blank=True, max_length=20, verbose_name="code postal"
                    ),
                ),
                (
                    "location_state",
                    models.CharField(blank=True, max_length=40, verbose_name="état"),
                ),
                (
                    "location_country",
                    django_countries.fields.CountryField(
                        blank=True, default="FR", max_length=2, verbose_name="pays"
                    ),
                ),
                ("email", models.EmailField(max_length=255, verbose_name="email")),
                ("first_name", models.CharField(max_length=255, verbose_name="prénom")),
                (
                    "last_name",
                    models.CharField(max_length=255, verbose_name="nom de famille"),
                ),
                (
                    "phone_number",
                    phonenumber_field.modelfields.PhoneNumberField(
                        max_length=128,
                        null=True,
                        region=None,
                        verbose_name="numéro de téléphone",
                    ),
                ),
                (
                    "type",
                    models.CharField(choices=[], max_length=255, verbose_name="type"),
                ),
                (
                    "mode",
                    models.CharField(max_length=70, verbose_name="Mode de paiement"),
                ),
                ("price", agir.payments.model_fields.AmountField(verbose_name="Prix")),
                (
                    "status",
                    models.IntegerField(
                        choices=[
                            (0, "Paiement en attente"),
                            (1, "Paiement terminé"),
                            (2, "Paiement abandonné en cours"),
                            (3, "Paiement annulé avant encaissement"),
                            (4, "Paiement refusé par votre banque"),
                            (-1, "Paiement remboursé"),
                        ],
                        default=0,
                        verbose_name="status",
                    ),
                ),
                ("meta", models.JSONField(blank=True, default=dict)),
                (
                    "events",
                    models.JSONField(
                        blank=True, default=list, verbose_name="Événements de paiement"
                    ),
                ),
                (
                    "person",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="payments",
                        to="people.person",
                    ),
                ),
                (
                    "subscription",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="payments",
                        to="payments.subscription",
                    ),
                ),
            ],
            options={
                "verbose_name": "Paiement",
                "verbose_name_plural": "Paiements",
                "ordering": ("-created",),
                "get_latest_by": "created",
            },
        ),
        migrations.RunSQL(
            "CREATE INDEX systempay_id ON payments_payment (mod(id, 900000))",
            reverse_sql="DROP INDEX systempay_id;",
        ),
    ]
