# Path: user_resource/models.py
# class SentMessage(models.Model):
#     message_id = models.CharField(max_length=256)
#     sender = models.ForeignKey(Application)
#     user = models.ForeignKey(User)
#     status = models.BooleanField(default=True)
#     error_message = models.TextField(null=True, blank=True)
#     created = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return self.message_id
# 
# Path: user_resource/oauth.py
# DEFAULT_FIELDS = ['id', ]
# 
# SCOPE_TO_FIELD_MAP = {
#     'basic': ['id', ],
#     'profile': ['first_name', 'last_name', 'type', 'is_alumni', ],
#     'sex': ['sex', ],
#     'picture': ['profile_picture'],
#     'ldap': ['username', 'email'],
#     'phone': ['contacts', 'mobile', ],
#     'insti_address': ['insti_address', ],
#     'program': ['program', 'roll_number', ],
#     'secondary_emails': ['secondary_emails', ],
#     'send_mail': [],
# }
# 
# USER_FIELDS = [
#     'username',
#     'first_name',
#     'last_name',
#     'type',
#     'is_alumni',
#     'sex',
#     'profile_picture',
#     'email',
#     'program',
#     'secondary_emails',
#     'contacts',
#     'insti_address',
#     'mobile',
#     'roll_number',
# ]
# 
# Path: user_resource/serializers.py
# class SendMailSerializer(serializers.Serializer):  # pylint: disable=abstract-method
#     subject = serializers.CharField()
#     message = serializers.CharField()
#     reply_to = serializers.ListField(
#         child=serializers.EmailField()
#     )
# 
# class UserSerializer(serializers.ModelSerializer):
#     program = ProgramSerializer()
#     secondary_emails = SecondaryEmailSerializer(many=True)
#     contacts = ContactNumberSerializer(many=True)
#     insti_address = InstituteAddressSerializer()
#     mobile = serializers.CharField(source='userprofile.mobile')
#     roll_number = serializers.CharField(source='userprofile.roll_number')
#     profile_picture = serializers.ImageField(source='userprofile.profile_picture')
#     sex = serializers.CharField(source='userprofile.sex')
#     type = serializers.CharField(source='userprofile.type')
#     is_alumni = serializers.BooleanField(source='userprofile.is_alumni')
# 
#     def __init__(self, *args, **kwargs):
#         super(UserSerializer, self).__init__(*args, **kwargs)
#         fields = self.context.get('fields')
#         if not isinstance(fields, list) and not isinstance(fields, set):
#             fields = []
#         fields.extend(DEFAULT_FIELDS)
# 
#         if fields is not None:
#             allowed = set(fields)
#             existing = set(self.fields.keys())
#             fields_to_remove = existing - allowed
#             for field in fields_to_remove:
#                 self.fields.pop(field)
# 
#     class Meta:
#         model = User
#         fields = copy.deepcopy(DEFAULT_FIELDS).extend(USER_FIELDS)


import logging
from smtplib import SMTPException
from django.contrib.auth.models import User
from django.core.mail import EmailMessage
from oauth2_provider.ext.rest_framework.permissions import TokenHasScope
from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.response import Response
from rest_framework.status import HTTP_400_BAD_REQUEST
from ..models import SentMessage
from ..oauth import DEFAULT_FIELDS, SCOPE_TO_FIELD_MAP, USER_FIELDS
from ..serializers import SendMailSerializer, UserSerializer



logger = logging.getLogger(__name__)


class UserViewset(viewsets.GenericViewSet):
    required_scopes = ['basic']
    permission_classes = [TokenHasScope]

# Path: user_resource/models.py
# class SentMessage(models.Model):
#     message_id = models.CharField(max_length=256)
#     sender = models.ForeignKey(Application)
#     user = models.ForeignKey(User)
#     status = models.BooleanField(default=True)
#     error_message = models.TextField(null=True, blank=True)
#     created = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return self.message_id
# 
# Path: user_resource/oauth.py
# DEFAULT_FIELDS = ['id', ]
# 
# SCOPE_TO_FIELD_MAP = {
#     'basic': ['id', ],
#     'profile': ['first_name', 'last_name', 'type', 'is_alumni', ],
#     'sex': ['sex', ],
#     'picture': ['profile_picture'],
#     'ldap': ['username', 'email'],
#     'phone': ['contacts', 'mobile', ],
#     'insti_address': ['insti_address', ],
#     'program': ['program', 'roll_number', ],
#     'secondary_emails': ['secondary_emails', ],
#     'send_mail': [],
# }
# 
# USER_FIELDS = [
#     'username',
#     'first_name',
#     'last_name',
#     'type',
#     'is_alumni',
#     'sex',
#     'profile_picture',
#     'email',
#     'program',
#     'secondary_emails',
#     'contacts',
#     'insti_address',
#     'mobile',
#     'roll_number',
# ]
# 
# Path: user_resource/serializers.py
# class SendMailSerializer(serializers.Serializer):  # pylint: disable=abstract-method
#     subject = serializers.CharField()
#     message = serializers.CharField()
#     reply_to = serializers.ListField(
#         child=serializers.EmailField()
#     )
# 
# class UserSerializer(serializers.ModelSerializer):
#     program = ProgramSerializer()
#     secondary_emails = SecondaryEmailSerializer(many=True)
#     contacts = ContactNumberSerializer(many=True)
#     insti_address = InstituteAddressSerializer()
#     mobile = serializers.CharField(source='userprofile.mobile')
#     roll_number = serializers.CharField(source='userprofile.roll_number')
#     profile_picture = serializers.ImageField(source='userprofile.profile_picture')
#     sex = serializers.CharField(source='userprofile.sex')
#     type = serializers.CharField(source='userprofile.type')
#     is_alumni = serializers.BooleanField(source='userprofile.is_alumni')
# 
#     def __init__(self, *args, **kwargs):
#         super(UserSerializer, self).__init__(*args, **kwargs)
#         fields = self.context.get('fields')
#         if not isinstance(fields, list) and not isinstance(fields, set):
#             fields = []
#         fields.extend(DEFAULT_FIELDS)
# 
#         if fields is not None:
#             allowed = set(fields)
#             existing = set(self.fields.keys())
#             fields_to_remove = existing - allowed
#             for field in fields_to_remove:
#                 self.fields.pop(field)
# 
#     class Meta:
#         model = User
#         fields = copy.deepcopy(DEFAULT_FIELDS).extend(USER_FIELDS)


# Path: user_resource/views/api.py
import logging
from smtplib import SMTPException
from django.contrib.auth.models import User
from django.core.mail import EmailMessage
from oauth2_provider.ext.rest_framework.permissions import TokenHasScope
from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.response import Response
from rest_framework.status import HTTP_400_BAD_REQUEST
from ..models import SentMessage
from ..oauth import DEFAULT_FIELDS, SCOPE_TO_FIELD_MAP, USER_FIELDS
from ..serializers import SendMailSerializer, UserSerializer




logger = logging.getLogger(__name__)


class UserViewset(viewsets.GenericViewSet):
    required_scopes = ['basic']
    permission_classes = [TokenHasScope]

    serializer_class = UserSerializer