import { Wallet } from '@cmdcode/signer';
import { gen_membership, get_membership, has_membership, } from '../../lib/member.js';
export function gen_membership_api(client) {
    return (index) => {
        const idx = index ?? client._gen_idx();
        return gen_membership(idx, client._signer, client._wallet);
    };
}
export function has_membership_api(client) {
    return (proposal) => {
        return has_membership(proposal.members, client._signer);
    };
}
export function claim_membership_api(client) {
    return (proposal) => {
        if (!has_membership(proposal.members, client._signer)) {
            throw new Error('not a member of the proposal');
        }
        const mship = get_membership(proposal.members, client._signer);
        return {
            data: mship,
            signer: client._signer.get_id(mship.id),
            wallet: new Wallet(mship.xpub)
        };
    };
}
export default function (client) {
    return {
        claim: claim_membership_api(client),
        exists: has_membership_api(client),
        generate: gen_membership_api(client)
    };
}
