from .base import (
    AssetSchema,
    CERBERUS_RULE_REQUIRED_NONEMPTY_STRING,
    CERBERUS_RULE_OPTIONAL_STRING,
    CERBERUS_RULE_TAXONOMY_TOPIC_LIST,
    ImageSchema,
)


class SitemapURLSchema(AssetSchema):
    def __init__(self):
        super(SitemapURLSchema, self).__init__()
        self['url'] = CERBERUS_RULE_REQUIRED_NONEMPTY_STRING
        self['canonical_url'] = CERBERUS_RULE_OPTIONAL_STRING
        self['genres'] = CERBERUS_RULE_TAXONOMY_TOPIC_LIST
        self['title'] = CERBERUS_RULE_REQUIRED_NONEMPTY_STRING
        self['keywords'] = {
            'type': 'list',
            'default': [],
            'schema': {'type': 'string'}
        }
        self['change_frequency'] = {
            'type': 'string',
            'allowed': ['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'],
            'nullable': True,
            'default': None
        }
        self['priority'] = {
            'type': 'float',
            'nullable': True,
            'default': None
        }
        # ********* Media assets *********
        self['images'] = {
            'type': 'list',
            'required': False,
            'default': [],
            'schema': {
                'type': 'dict',
                'schema': ImageSchema()
            }
        }
        self['localizations'] = {
            'type': 'list',
            'required': False,
            'default': [],
            'schema': {
                'type': 'dict',
                'schema': {
                    'language': CERBERUS_RULE_REQUIRED_NONEMPTY_STRING,
                    'url': CERBERUS_RULE_REQUIRED_NONEMPTY_STRING
                }
            }
        }
