from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _

from oscar.apps.address.abstract_models import AbstractUserAddress as BaseUserAddress

from .mixins import AddressMixin


class AbstractUserAddress(BaseUserAddress, AddressMixin):
    house_number = models.CharField(_("No."), blank=True, null=True, max_length=255)
    email = models.EmailField(_("Email"), blank=True, null=False)

    # base_fields is used in the summary, it is only for display.
    # hash_fields is used to determine if an address allrady exists.
    # billing address and shipping address, get the definition of hash_fields
    # and base_fields fron this class, so they need to be changed only here.
    base_fields = hash_fields = settings.OSCAR_ADDRESS_HASH_FIELDS

    def active_address_fields(self):
        """
        Returns the non-empty components of the address, but merging the
        title, first_name and last_name into a single line. It uses fields
        listed out in `base_fields` property, ordered by the
        `OSCAR_ADDRESS_BASE_FIELD_ORDER` setting.
        """

        return self.get_address_field_values(self.ordered_base_fields)

    class Meta(BaseUserAddress.Meta):
        abstract = True
