class HeadlessB2BOrganizationClient {
    _networkClient;
    _apiNetworkClient;
    _subscriptionService;
    constructor(_networkClient, _apiNetworkClient, _subscriptionService){
        this._networkClient = _networkClient;
        this._apiNetworkClient = _apiNetworkClient;
        this._subscriptionService = _subscriptionService;
    }
    get = async ()=>{
        const resp = await this._networkClient.fetchSDK({
            url: `/b2b/organizations/me`,
            method: 'GET'
        });
        this._subscriptionService.updateOrganization(resp.organization);
        return resp.organization;
    };
    getSync = ()=>{
        return this._subscriptionService.getOrganization();
    };
    getInfo = ()=>({
            organization: this.getSync(),
            fromCache: this._subscriptionService.getFromCache()
        });
    onChange = (callback)=>{
        return this._subscriptionService.subscribeToState((state)=>callback(state?.organization ?? null));
    };
    update = async (data)=>{
        const resp = await this._networkClient.fetchSDK({
            url: `/b2b/organizations/me`,
            method: 'PUT',
            body: data
        });
        this._subscriptionService.updateOrganization(resp.organization);
        return resp;
    };
    delete = async ()=>{
        const resp = await this._networkClient.fetchSDK({
            url: `/b2b/organizations/me`,
            method: 'DELETE'
        });
        this._subscriptionService.destroyState();
        return resp;
    };
    getBySlug = async (data)=>{
        return this._networkClient.fetchSDK({
            url: `/b2b/organizations/search`,
            method: 'POST',
            body: data
        });
    };
    getConnectedApps = async ()=>{
        return this._networkClient.fetchSDK({
            url: '/b2b/organizations/connected_apps',
            method: 'GET'
        });
    };
    getConnectedApp = async (data)=>{
        return this._networkClient.fetchSDK({
            url: `/b2b/organizations/connected_apps/${data.connected_app_id}`,
            method: 'GET'
        });
    };
    members = {
        create: async (data)=>{
            return this._networkClient.fetchSDK({
                url: `/b2b/organizations/members`,
                method: 'POST',
                body: data
            });
        },
        search: async (data)=>{
            return this._networkClient.fetchSDK({
                url: `/b2b/organizations/me/members/search`,
                method: 'POST',
                body: data
            });
        },
        update: async (data)=>{
            const response = await this._networkClient.fetchSDK({
                url: `/b2b/organizations/members/${data.member_id}`,
                method: 'PUT',
                body: data
            });
            this.updateMemberIfSelf(response);
            return response;
        },
        deletePassword: async (passwordId)=>{
            const response = await this._networkClient.fetchSDK({
                url: `/b2b/organizations/members/passwords/${passwordId}`,
                method: 'DELETE'
            });
            this.updateMemberIfSelf(response);
            return response;
        },
        deleteMFAPhoneNumber: async (memberId)=>{
            const response = await this._networkClient.fetchSDK({
                url: `/b2b/organizations/members/mfa_phone_numbers/${memberId}`,
                method: 'DELETE'
            });
            this.updateMemberIfSelf(response);
            return response;
        },
        deleteMFATOTP: async (memberId)=>{
            const response = await this._networkClient.fetchSDK({
                url: `/b2b/organizations/members/totp/${memberId}`,
                method: 'DELETE'
            });
            this.updateMemberIfSelf(response);
            return response;
        },
        delete: async (memberId)=>{
            const response = await this._networkClient.fetchSDK({
                url: `/b2b/organizations/members/${memberId}`,
                method: 'DELETE'
            });
            if (memberId === this._subscriptionService.getMember()?.member_id) {
                this._subscriptionService.destroyState();
            }
            return response;
        },
        reactivate: async (memberId)=>{
            return this._networkClient.fetchSDK({
                url: `/b2b/organizations/members/${memberId}/reactivate`,
                method: 'PUT'
            });
        },
        unlinkRetiredEmail: async (data)=>{
            const { member_id, ...body } = data;
            const response = await this._apiNetworkClient.fetchSDK({
                url: `/b2b/organizations/members/${member_id}/unlink_retired_email`,
                method: 'POST',
                body
            });
            this.updateMemberIfSelf(response);
            return response;
        },
        startEmailUpdate: async (data)=>{
            const { member_id, ...body } = data;
            const response = await this._apiNetworkClient.fetchSDK({
                url: `/b2b/organizations/members/${member_id}/start_email_update`,
                method: 'POST',
                body
            });
            this.updateMemberIfSelf(response);
            return response;
        },
        getConnectedApps: async (data)=>{
            return this._networkClient.fetchSDK({
                url: `b2b/organizations/members/${data.member_id}/connected_apps`,
                method: 'GET'
            });
        },
        revokeConnectedApp: async (data)=>{
            return this._networkClient.fetchSDK({
                url: `/b2b/organizations/members/${data.member_id}/connected_apps/${data.connected_app_id}/revoke`,
                method: 'POST'
            });
        }
    };
    updateMemberIfSelf = (response)=>{
        if (response.member_id === this._subscriptionService.getMember()?.member_id) {
            this._subscriptionService.updateMember(response.member);
        }
    };
}

export { HeadlessB2BOrganizationClient };
//# sourceMappingURL=HeadlessB2BOrganizationClient.mjs.map
