import { Pda } from '../../../types';
import { assert } from '../../../utils';
/** @group Model Helpers */
export const isAuctionHouse = (value) => typeof value === 'object' && value.model === 'auctionHouse';
/** @group Model Helpers */
export function assertAuctionHouse(value) {
    assert(isAuctionHouse(value), `Expected AuctionHouse type`);
}
/** @group Model Helpers */
export const isAuctioneerAuctionHouse = (value) => isAuctionHouse(value) && value.hasAuctioneer;
/** @group Model Helpers */
export function assertAuctioneerAuctionHouse(value) {
    assert(isAuctioneerAuctionHouse(value), `Expected AuctioneerAuctionHouse type`);
}
/** @group Model Helpers */
export const toAuctionHouse = (auctionHouseAccount, treasuryMint, auctioneerAccount) => {
    if (auctionHouseAccount.data.hasAuctioneer) {
        assert(!!auctioneerAccount, 'Auctioneer account is required when hasAuctioneer is true');
        assert(!!auctioneerAccount &&
            auctioneerAccount.data.auctionHouse.equals(auctionHouseAccount.publicKey), 'Auctioneer account does not match the AuctionHouse account');
    }
    return Object.assign({ model: 'auctionHouse', address: new Pda(auctionHouseAccount.publicKey, auctionHouseAccount.data.bump), creatorAddress: auctionHouseAccount.data.creator, authorityAddress: auctionHouseAccount.data.authority, treasuryMint, feeAccountAddress: new Pda(auctionHouseAccount.data.auctionHouseFeeAccount, auctionHouseAccount.data.feePayerBump), treasuryAccountAddress: new Pda(auctionHouseAccount.data.auctionHouseTreasury, auctionHouseAccount.data.treasuryBump), feeWithdrawalDestinationAddress: auctionHouseAccount.data.feeWithdrawalDestination, treasuryWithdrawalDestinationAddress: auctionHouseAccount.data.treasuryWithdrawalDestination, sellerFeeBasisPoints: auctionHouseAccount.data.sellerFeeBasisPoints, requiresSignOff: auctionHouseAccount.data.requiresSignOff, canChangeSalePrice: auctionHouseAccount.data.canChangeSalePrice, isNative: treasuryMint.isWrappedSol }, (auctionHouseAccount.data.hasAuctioneer && auctioneerAccount
        ? {
            hasAuctioneer: true,
            auctioneer: {
                address: auctioneerAccount.publicKey,
                authority: auctioneerAccount.data.auctioneerAuthority,
                scopes: auctioneerAccount.data.scopes.reduce((acc, isAllowed, index) => (isAllowed ? [...acc, index] : acc), []),
            },
        }
        : { hasAuctioneer: false }));
};
//# sourceMappingURL=AuctionHouse.js.map