import { Buffer } from 'buffer';
import { gatekeeperBeet, } from '@metaplex-foundation/mpl-candy-guard';
import { createSerializerFromBeet, mapSerializer, Pda, } from '../../../types';
/** @internal */
export const gatekeeperGuardManifest = {
    name: 'gatekeeper',
    settingsBytes: 33,
    settingsSerializer: mapSerializer(createSerializerFromBeet(gatekeeperBeet), (settings) => (Object.assign(Object.assign({}, settings), { network: settings.gatekeeperNetwork })), (settings) => (Object.assign(Object.assign({}, settings), { gatekeeperNetwork: settings.network }))),
    mintSettingsParser: ({ metaplex, settings, mintSettings, payer, programs, }) => {
        var _a;
        const gatewayProgram = metaplex.programs().getGateway(programs);
        const tokenAccount = (_a = mintSettings === null || mintSettings === void 0 ? void 0 : mintSettings.tokenAccount) !== null && _a !== void 0 ? _a : Pda.find(gatewayProgram.address, [
            payer.publicKey.toBuffer(),
            Buffer.from('gateway'),
            Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]),
            settings.network.toBuffer(),
        ]);
        const remainingAccounts = [
            {
                isSigner: false,
                address: tokenAccount,
                isWritable: true,
            },
        ];
        if (settings.expireOnUse) {
            const expireAccount = Pda.find(gatewayProgram.address, [
                settings.network.toBuffer(),
                Buffer.from('expire'),
            ]);
            remainingAccounts.push({
                isSigner: false,
                address: gatewayProgram.address,
                isWritable: false,
            });
            remainingAccounts.push({
                isSigner: false,
                address: expireAccount,
                isWritable: false,
            });
        }
        return {
            arguments: Buffer.from([]),
            remainingAccounts,
        };
    },
};
//# sourceMappingURL=gatekeeper.js.map