from office365.runtime.client_object import ClientObject
from office365.runtime.client_result import ClientResult
from office365.runtime.http.http_method import HttpMethod
from office365.runtime.queries.service_operation_query import ServiceOperationQuery
from office365.runtime.resource_path import ResourcePath
from office365.sharepoint.portal.group_creation_params import GroupCreationInformation
from office365.sharepoint.portal.group_site_info import GroupSiteInfo


class GroupSiteManager(ClientObject):
    def __init__(self, context):
        super(GroupSiteManager, self).__init__(context, ResourcePath("GroupSiteManager"), None)

    def create_group_ex(self, display_name, alias, is_public, optional_params=None):
        """
        Create a modern site

        :param str display_name:
        :param str alias:
        :param bool is_public:
        :param office365.sharepoint.portal.group_creation_params.GroupCreationParams or None optional_params:
        """
        payload = GroupCreationInformation(display_name, alias, is_public, optional_params)
        result = ClientResult(self.context, GroupSiteInfo())
        qry = ServiceOperationQuery(self, "CreateGroupEx", None, payload, None, result)
        self.context.add_query(qry)
        return result

    def delete(self, site_url):
        """
        Deletes a SharePoint Team site

        :type site_url: str
        """
        payload = {
            "siteUrl": site_url
        }
        qry = ServiceOperationQuery(self, "Delete", None, payload)
        self.context.add_query(qry)
        return self

    def get_status(self, group_id):
        """Get the status of a SharePoint site

        :type group_id: str
        """
        result = ClientResult(self.context, GroupSiteInfo())
        qry = ServiceOperationQuery(self, "GetSiteStatus", None, {'groupId': group_id}, None, result)
        self.context.add_query(qry)

        def _construct_status_request(request):
            request.method = HttpMethod.Get
            request.url += "?groupId='{0}'".format(group_id)

        self.context.before_execute(_construct_status_request)
        return result

[((23, 18, 23, 91), 'office365.sharepoint.portal.group_creation_params.GroupCreationInformation', 'GroupCreationInformation', ({(23, 43, 23, 55): 'display_name', (23, 57, 23, 62): 'alias', (23, 64, 23, 73): 'is_public', (23, 75, 23, 90): 'optional_params'}, {}), '(display_name, alias, is_public, optional_params)', False, 'from office365.sharepoint.portal.group_creation_params import GroupCreationInformation\n'), ((25, 14, 25, 87), 'office365.runtime.queries.service_operation_query.ServiceOperationQuery', 'ServiceOperationQuery', ({(25, 36, 25, 40): 'self', (25, 42, 25, 57): '"""CreateGroupEx"""', (25, 59, 25, 63): 'None', (25, 65, 25, 72): 'payload', (25, 74, 25, 78): 'None', (25, 80, 25, 86): 'result'}, {}), "(self, 'CreateGroupEx', None, payload, None, result)", False, 'from office365.runtime.queries.service_operation_query import ServiceOperationQuery\n'), ((38, 14, 38, 66), 'office365.runtime.queries.service_operation_query.ServiceOperationQuery', 'ServiceOperationQuery', ({(38, 36, 38, 40): 'self', (38, 42, 38, 50): '"""Delete"""', (38, 52, 38, 56): 'None', (38, 58, 38, 65): 'payload'}, {}), "(self, 'Delete', None, payload)", False, 'from office365.runtime.queries.service_operation_query import ServiceOperationQuery\n'), ((48, 14, 48, 101), 'office365.runtime.queries.service_operation_query.ServiceOperationQuery', 'ServiceOperationQuery', ({(48, 36, 48, 40): 'self', (48, 42, 48, 57): '"""GetSiteStatus"""', (48, 59, 48, 63): 'None', (48, 65, 48, 86): "{'groupId': group_id}", (48, 88, 48, 92): 'None', (48, 94, 48, 100): 'result'}, {}), "(self, 'GetSiteStatus', None, {'groupId': group_id},\n    None, result)", False, 'from office365.runtime.queries.service_operation_query import ServiceOperationQuery\n'), ((12, 56, 12, 88), 'office365.runtime.resource_path.ResourcePath', 'ResourcePath', ({(12, 69, 12, 87): '"""GroupSiteManager"""'}, {}), "('GroupSiteManager')", False, 'from office365.runtime.resource_path import ResourcePath\n'), ((24, 44, 24, 59), 'office365.sharepoint.portal.group_site_info.GroupSiteInfo', 'GroupSiteInfo', ({}, {}), '()', False, 'from office365.sharepoint.portal.group_site_info import GroupSiteInfo\n'), ((47, 44, 47, 59), 'office365.sharepoint.portal.group_site_info.GroupSiteInfo', 'GroupSiteInfo', ({}, {}), '()', False, 'from office365.sharepoint.portal.group_site_info import GroupSiteInfo\n')]