# -*- coding: utf-8 -*-
"""User models."""
from flask import current_app, url_for
from flask_babel import gettext
from flask_login import UserMixin
from fulfil_client.model import BooleanType, ModelType, One2ManyType, StringType
from itsdangerous import TimestampSigner, URLSafeSerializer

from shop.extensions import fulfil
from shop.fulfilio import Model
from shop.globals import current_channel
from shop.utils import render_email


class Address(Model):
    """
    An address of a user
    """
    __model_name__ = 'party.address'
    _eager_fields = set(['full_address'])

    party = ModelType('party.party')
    name = StringType(required=True)
    street = StringType()
    streetbis = StringType()
    zip = StringType()
    city = StringType()
    country = ModelType("country.country")
    subdivision = ModelType("country.subdivision")
    phone = StringType()
    validation_status = StringType()

    @property
    def full_address(self):
        return self._values.get('full_address', '').replace('\r\n', ', ')

    def serialize(self):
        values = self._values.copy()
        values['country'] = self.country and self.country.code