from django.db import models

from vaccine_card.vaccination.models import Vaccine


class State(models.Model):
    name = models.CharField(max_length=20, verbose_name='Nome')

    class Meta:
        verbose_name = 'Unidade Federativa'

    def __str__(self):
        return self.name


class City(models.Model):
    name = models.CharField(max_length=50, verbose_name='Nome')
    state = models.ForeignKey(State, on_delete=models.CASCADE, verbose_name=State._meta.verbose_name)

    class Meta:
        verbose_name = 'Município'

    def __str__(self):
        return self.name


class Address(models.Model):
    logradouro = models.CharField(max_length=150, verbose_name='Logradouro')
    numero = models.CharField(max_length=4, verbose_name='Número')
    complemento = models.CharField(max_length=50, null=True, blank=True, verbose_name='Complemento')
    bairro = models.CharField(max_length=150, verbose_name='Bairro')
    cep = models.CharField(max_length=8, verbose_name='CEP')

    # state = models.ForeignKey(State, on_delete=models.CASCADE, verbose_name=State._meta.verbose_name)
    city = models.ForeignKey(City, on_delete=models.CASCADE, verbose_name=City._meta.verbose_name)

    class Meta:
        verbose_name = 'Endereço'


class HealthCenter(models.Model):
    cnes = models.CharField(max_length=7, verbose_name='CNES')
    cnpj = models.CharField(max_length=14, verbose_name='CNPJ')
    name = models.CharField(max_length=255, verbose_name='Razão Social')

    created_at = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name='Criado em:')
    updated_at = models.DateTimeField(auto_now_add=False, auto_now=True, verbose_name='Atualizado em:')

    address = models.ManyToManyField(Address, verbose_name=Address._meta.verbose_name)

    class Meta:
        verbose_name = 'Estabelecimento de Saúde'
        verbose_name_plural = 'Estabelecimentos de Saúde'

    def __str__(self):
        return self.name


class Stock(models.Model):
    lot = models.PositiveSmallIntegerField(verbose_name='Lote')

    created_at = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name='Criado em:')
    updated_at = models.DateTimeField(auto_now_add=False, auto_now=True, verbose_name='Atualizado em:')

    health_center = models.ForeignKey(HealthCenter, on_delete=models.CASCADE,
                                      verbose_name=HealthCenter._meta.verbose_name)

    vaccines = models.ManyToManyField(Vaccine, through='VaccineStock', verbose_name=Vaccine._meta.verbose_name)

    class Meta:
        verbose_name = 'Estoque'


class VaccineStock(models.Model):
    amount = models.PositiveSmallIntegerField(verbose_name='Quantidade recebida')
    remaining = models.PositiveSmallIntegerField(verbose_name='Quantidade restante')

    vaccine = models.ForeignKey(Vaccine, on_delete=models.DO_NOTHING, verbose_name=Vaccine._meta.verbose_name)
    stock = models.ForeignKey(Stock, on_delete=models.DO_NOTHING, verbose_name=Stock._meta.verbose_name)

    class Meta:
        verbose_name = 'Estoque de Vacina'

    def __str__(self):
        return self.vaccine.name

[((122, 174), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(20)', 'verbose_name': '"""Nome"""'}), "(max_length=20, verbose_name='Nome')\n", (138, 174), False, 'from django.db import models\n'), ((324, 376), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(50)', 'verbose_name': '"""Nome"""'}), "(max_length=50, verbose_name='Nome')\n", (340, 376), False, 'from django.db import models\n'), ((389, 483), 'django.db.models.ForeignKey', 'models.ForeignKey', (['State'], {'on_delete': 'models.CASCADE', 'verbose_name': 'State._meta.verbose_name'}), '(State, on_delete=models.CASCADE, verbose_name=State._meta\n    .verbose_name)\n', (406, 483), False, 'from django.db import models\n'), ((628, 687), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(150)', 'verbose_name': '"""Logradouro"""'}), "(max_length=150, verbose_name='Logradouro')\n", (644, 687), False, 'from django.db import models\n'), ((701, 754), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(4)', 'verbose_name': '"""Número"""'}), "(max_length=4, verbose_name='Número')\n", (717, 754), False, 'from django.db import models\n'), ((773, 860), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(50)', 'null': '(True)', 'blank': '(True)', 'verbose_name': '"""Complemento"""'}), "(max_length=50, null=True, blank=True, verbose_name=\n    'Complemento')\n", (789, 860), False, 'from django.db import models\n'), ((869, 924), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(150)', 'verbose_name': '"""Bairro"""'}), "(max_length=150, verbose_name='Bairro')\n", (885, 924), False, 'from django.db import models\n'), ((935, 985), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(8)', 'verbose_name': '"""CEP"""'}), "(max_length=8, verbose_name='CEP')\n", (951, 985), False, 'from django.db import models\n'), ((1102, 1194), 'django.db.models.ForeignKey', 'models.ForeignKey', (['City'], {'on_delete': 'models.CASCADE', 'verbose_name': 'City._meta.verbose_name'}), '(City, on_delete=models.CASCADE, verbose_name=City._meta.\n    verbose_name)\n', (1119, 1194), False, 'from django.db import models\n'), ((1288, 1339), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(7)', 'verbose_name': '"""CNES"""'}), "(max_length=7, verbose_name='CNES')\n", (1304, 1339), False, 'from django.db import models\n'), ((1351, 1403), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(14)', 'verbose_name': '"""CNPJ"""'}), "(max_length=14, verbose_name='CNPJ')\n", (1367, 1403), False, 'from django.db import models\n'), ((1415, 1476), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(255)', 'verbose_name': '"""Razão Social"""'}), "(max_length=255, verbose_name='Razão Social')\n", (1431, 1476), False, 'from django.db import models\n'), ((1495, 1582), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)', 'auto_now': '(False)', 'verbose_name': '"""Criado em:"""'}), "(auto_now_add=True, auto_now=False, verbose_name=\n    'Criado em:')\n", (1515, 1582), False, 'from django.db import models\n'), ((1595, 1686), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(False)', 'auto_now': '(True)', 'verbose_name': '"""Atualizado em:"""'}), "(auto_now_add=False, auto_now=True, verbose_name=\n    'Atualizado em:')\n", (1615, 1686), False, 'from django.db import models\n'), ((1697, 1769), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['Address'], {'verbose_name': 'Address._meta.verbose_name'}), '(Address, verbose_name=Address._meta.verbose_name)\n', (1719, 1769), False, 'from django.db import models\n'), ((1983, 2036), 'django.db.models.PositiveSmallIntegerField', 'models.PositiveSmallIntegerField', ([], {'verbose_name': '"""Lote"""'}), "(verbose_name='Lote')\n", (2015, 2036), False, 'from django.db import models\n'), ((2055, 2142), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)', 'auto_now': '(False)', 'verbose_name': '"""Criado em:"""'}), "(auto_now_add=True, auto_now=False, verbose_name=\n    'Criado em:')\n", (2075, 2142), False, 'from django.db import models\n'), ((2155, 2246), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(False)', 'auto_now': '(True)', 'verbose_name': '"""Atualizado em:"""'}), "(auto_now_add=False, auto_now=True, verbose_name=\n    'Atualizado em:')\n", (2175, 2246), False, 'from django.db import models\n'), ((2263, 2371), 'django.db.models.ForeignKey', 'models.ForeignKey', (['HealthCenter'], {'on_delete': 'models.CASCADE', 'verbose_name': 'HealthCenter._meta.verbose_name'}), '(HealthCenter, on_delete=models.CASCADE, verbose_name=\n    HealthCenter._meta.verbose_name)\n', (2280, 2371), False, 'from django.db import models\n'), ((2421, 2522), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['Vaccine'], {'through': '"""VaccineStock"""', 'verbose_name': 'Vaccine._meta.verbose_name'}), "(Vaccine, through='VaccineStock', verbose_name=\n    Vaccine._meta.verbose_name)\n", (2443, 2522), False, 'from django.db import models\n'), ((2617, 2685), 'django.db.models.PositiveSmallIntegerField', 'models.PositiveSmallIntegerField', ([], {'verbose_name': '"""Quantidade recebida"""'}), "(verbose_name='Quantidade recebida')\n", (2649, 2685), False, 'from django.db import models\n'), ((2702, 2770), 'django.db.models.PositiveSmallIntegerField', 'models.PositiveSmallIntegerField', ([], {'verbose_name': '"""Quantidade restante"""'}), "(verbose_name='Quantidade restante')\n", (2734, 2770), False, 'from django.db import models\n'), ((2786, 2887), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Vaccine'], {'on_delete': 'models.DO_NOTHING', 'verbose_name': 'Vaccine._meta.verbose_name'}), '(Vaccine, on_delete=models.DO_NOTHING, verbose_name=\n    Vaccine._meta.verbose_name)\n', (2803, 2887), False, 'from django.db import models\n'), ((2895, 2992), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Stock'], {'on_delete': 'models.DO_NOTHING', 'verbose_name': 'Stock._meta.verbose_name'}), '(Stock, on_delete=models.DO_NOTHING, verbose_name=Stock.\n    _meta.verbose_name)\n', (2912, 2992), False, 'from django.db import models\n')]