from guardian.shortcuts import get_perms
from rest_framework import serializers as ser
from rest_framework.exceptions import ValidationError

from api.actions.serializers import ReviewableCountsRelationshipField
from api.base.utils import absolute_reverse, get_user_auth
from api.base.serializers import JSONAPISerializer, IDField, LinksField, RelationshipField, TypeField, TypedRelationshipField
from api.providers.permissions import GROUPS
from api.providers.workflows import Workflows
from osf.models.user import Email, OSFUser
from osf.models.validators import validate_email
from website import mails
from website.settings import DOMAIN


class ProviderSerializer(JSONAPISerializer):

    class Meta:
        type_ = 'providers'

    name = ser.CharField(read_only=True)
    description = ser.CharField(read_only=True)
    id = ser.CharField(read_only=True, max_length=200, source='_id')
    advisory_board = ser.CharField(read_only=True)
    example = ser.CharField(read_only=True, allow_null=True)
    domain = ser.CharField(read_only=True, allow_null=False)
    domain_redirect_enabled = ser.BooleanField(read_only=True)
    footer_links = ser.CharField(read_only=True)
    email_support = ser.CharField(read_only=True, allow_null=True)
    facebook_app_id = ser.IntegerField(read_only=True, allow_null=True)
    allow_submissions = ser.BooleanField(read_only=True)
    allow_commenting = ser.BooleanField(read_only=True)
    assets = ser.SerializerMethodField(read_only=True)

    links = LinksField({
        'self': 'get_absolute_url',
        'external_url': 'get_external_url'
    })

    taxonomies = TypedRelationshipField(
        related_view='providers:taxonomy-list',
        related_view_kwargs={'provider_id': '<_id>'}
    )

    highlighted_taxonomies = TypedRelationshipField(
        related_view='providers:highlighted-taxonomy-list',