# -*- coding: utf-8 -*-
import os

from werkzeug import exceptions

APP_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

DEBUG = False
HOST = '0.0.0.0'
LISTEN_PORT = None
THREADED_SERVER = DEBUG
HTTP_SCHEME_HEADER = 'X-Forwarded-Proto'

ELASTICSEARCH_HOSTS = ['localhost']

# Don't expose urls on 404s
ERROR_404_HELP = False

# RSS required channel elements
RSS_DEFAULT_VALUES = {
    'title': 'National Geographic Global Feed',
    'description': 'Natgeo\'s global feed'
}

# Available options are: console, file and syslog
LOGGING_HANDLERS = ['file', ]
LOGGING_LEVEL = 'WARN'
LOGGING_FILE_NAME = 'distribution.log'
LOGGING_SYSLOG_TAG = 'DISTRIBUTION'

# Hide results by source feed
SOURCE_BLACKLIST = []

TAXONOMY_TOPIC_TYPES = [
    'audiences',
    'concepts',
    'events',
    'genres',
    'locations',
    'organizations',
    'persons',
    'series',
    'sources',
    'subjects'
]

# Available filters for the FeedItem manager
FEED_ITEM_FILTERS = {
    'collection': 'collection_id',
    'content_type': 'content_type',
    'domain': 'meta.domain',
    'series.id': ['series_id', 'episode.series_id'],
    'uri': 'uri',
    'id': 'id',
}
for topic_type in TAXONOMY_TOPIC_TYPES:
    FEED_ITEM_FILTERS[topic_type] = topic_type
del topic_type

FEED_ITEM_FILTERS_WITHOUT_DEFAULT_DATETIME = [
    'uri',
    'id',
    'title-abstract',
    'series.id'
]

# Output Result
MAX_ROWS_LIMIT = 40
MAX_DAYS_LIMIT = 14

# Flask-api-auth
ROLE_MANAGER = 'distribution.managers.auth.RoleManager'
APIUSER_MANAGER = 'distribution.managers.auth.APIUserManager'

# Flask-api-User-Key
API_AUTH_API_USER = 'ApiAuth-ApiUser'
API_AUTH_API_KEY = 'ApiAuth-ApiKey'

DEFAULT_ADAPTER_MODEL = "TemplatedJSONOutputAdapter"

EXTRA_ADAPTERS = {
    "rss_embedded": {
        "adapter": "RSSOutputAdapter",
        "context": {
            "item_template": "feed-embedded-item.rss"
        }
    },
    "rss_msn": {
        "adapter": "RSSOutputAdapter",
        "context": {
            "item_template": "feed-msn.rss"
        }
    },
    "rss_newsstand": {
        "adapter": "RSSOutputAdapter",
        "context": {
            "item_template": "feed-newsstand.rss"
        }
    }
}

# Google AMP
AMP_OUTPUT_FOLDER = '/efs/webapp/amp_result/'
AMP_ITEM_ENDPOINT = 'http://127.0.0.1/api/v1/item/{}'
AMP_API_USER = 'amp'
AMP_API_KEY = '224f39f9395056585aceb3b8c3a6493d91d56ee4'
AMP_CACHE_ENABLED = False
AMP_CACHE_URL = 'https://cdn.ampproject.org/'
AMP_PUBLIC_HOST = 'relay.nationalgeographic.com/proxy/distribution'

SEQUENCER_MODELS_MAP = {
    'article': 'distribution.models.article.Article',
    'mediaimage': 'distribution.models.mediaimage.MediaImage',
    'mediaphoto': 'distribution.models.mediaphoto.MediaPhoto',
    'mediavideo': 'distribution.models.mediavideo.MediaVideo',
    'featuredimage': 'distribution.models.featured_image.FeaturedImage',
    'featuredimagecollection': ('distribution.models.featured_image_collection.'
                                'FeaturedImageCollection'),
    'feeditem': 'distribution.models.feed.FeedItem',
    'magazine': 'distribution.models.magazine.Magazine',
    'magazineissue': 'distribution.models.magazine_issue.MagazineIssue',
    'series': 'distribution.models.series.Series',
    'schedule': 'distribution.models.schedule.Schedule',
    'taxonomytopic': 'distribution.models.taxonomy.TaxonomyTopic',
    'featuredtext': 'distribution.models.featured_text.FeaturedText',
    'sitemapurl': 'distribution.models.sitemap_url.SitemapURL',
}

MODELS_MAP = dict(
    apirole='flask_api_auth.models.APIRole',
    apiuser='flask_api_auth.models.APIUser',
    **SEQUENCER_MODELS_MAP
)

SOURCE_SYSTEM_IDS = ["mpx-us", "neulion-au", "yourshot-us", "aem-us", "chook-au", "Getty"]

SENTRY_CONFIG = {
    'ignore_exceptions': [
        exc.__name__ for code, exc in exceptions.default_exceptions.items() if code in [401, 403, 404]],
}

ADVENTURE = 'Adventure'
ANIMALS = 'Animals'
NEWS = 'News'
PHOTOGRAPHY = 'Photography'
TRAVEL = 'Travel'
CULTURE_EXPLORATION = 'Culture & Exploration'
GLOBALSITES = 'gs'

SOURCES_MAP = {
    ADVENTURE: 'fa2b96a6-d3be-3cfb-b536-95ea3b519b57',
    ANIMALS: 'fa010584-7bbf-3e92-90f9-586bb27fce94',
    NEWS: '2ea1233d-1a91-36a5-b06b-52819a1fd03c',
    PHOTOGRAPHY: '8e8d45f6-7f3b-355f-8fea-71cbd8fedb1d',
    TRAVEL: '432c4f83-2d55-3974-b95f-a221c87c0fd1',
    CULTURE_EXPLORATION: '2c4e21f7-174a-3808-9059-a420095df149',
}

GENRES_MAP = {
    NEWS: '9f181472-1cd4-3c9c-b3fd-ecc6596912fc',
    ANIMALS: '4729be72-b8b0-34f6-88d5-0ffb5b256a38'
}

FEED_DEFAULT_CONTENT_TYPES = [
    'article:story',
    'article:image_gallery',
    'featured_image',
    'collection:featured_image',
    'featured_text'
]

# Sitemap Output Result
SITEMAP_MAX_ROWS_LIMIT = 1000
SITEMAP_MAX_ARTICLE_LIMIT = 100
SITEMAP_MAX_DAYS_TO_SEARCH = 2
SITEMAP_ALLOWED_SUBDOMAINS = [
    'animals',
    'environment',
    'travel',
    'science',
    'culture',
    'photography',
    'magazine',
]

NATGEO_ALLOWED_DOMAINS = [
    'www.nationalgeographic.com',
    'www-staging.nationalgeographic.com',
    'www-uat6.int.ngeo.com',
    'www-qa6.int.ngeo.com',
]
