# Path: invenio_communities/proxies.py

# 
# Path: invenio_communities/invitations/services/schemas.py
# class MemberInvitationPayloadSchema(RequestSchema):
#     """Community Member Invitation Schema."""
# 
#     role = fields.String(required=True)
# 
#     @validates("role")
#     def validate_role(self, value):
#         """Validate role."""
#         return validate.OneOf(ROLE_TYPES)


from flask_babelex import lazy_gettext as _
from invenio_requests.customizations import RequestAction, RequestState, \
    BaseRequestType
from ...proxies import current_communities
from .schemas import MemberInvitationPayloadSchema
# Copyright (C) 2022 Northwestern University.
#
# Invenio-Communities is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"""Invitation request types."""



# Actions

class AcceptAction(RequestAction):
    """Accept action."""

    status_from = ['open']
    status_to = 'accepted'

    def can_execute(self, identity):
        """Check if the accept action can be executed."""
        # TODO
        return True

    def execute(self, identity, uow):
        """Accept entity into community."""
        member_data = {
            **self.request.receiver.reference_dict,
            **self.request.topic.reference_dict,
            "role": self.request["payload"]["role"]
        }


# Path: invenio_communities/proxies.py

# 
# Path: invenio_communities/invitations/services/schemas.py
# class MemberInvitationPayloadSchema(RequestSchema):
#     """Community Member Invitation Schema."""
# 
#     role = fields.String(required=True)
# 
#     @validates("role")
#     def validate_role(self, value):
#         """Validate role."""
#         return validate.OneOf(ROLE_TYPES)


# Path: invenio_communities/invitations/services/request_types.py
from flask_babelex import lazy_gettext as _
from invenio_requests.customizations import RequestAction, RequestState, \
    BaseRequestType
from ...proxies import current_communities
from .schemas import MemberInvitationPayloadSchema

# Copyright (C) 2022 Northwestern University.
#
# Invenio-Communities is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"""Invitation request types."""



# Actions

class AcceptAction(RequestAction):
    """Accept action."""

    status_from = ['open']
    status_to = 'accepted'

    def can_execute(self, identity):
        """Check if the accept action can be executed."""
        # TODO
        return True

    def execute(self, identity, uow):
        """Accept entity into community."""
        member_data = {
            **self.request.receiver.reference_dict,
            **self.request.topic.reference_dict,
            "role": self.request["payload"]["role"]
        }


        current_communities.service.members.create(