import { amount, lamports, toBigNumber, toDateTime, } from '../../../types';
import { assert } from '../../../utils';
export const isPurchase = (value) => typeof value === 'object' && value.model === 'purchase' && !value.lazy;
export function assertPurchase(value) {
    assert(isPurchase(value), `Expected Purchase type`);
}
export const toPurchase = (account, auctionHouseModel, asset) => {
    const lazyPurchase = toLazyPurchase(account, auctionHouseModel);
    return Object.assign(Object.assign({}, lazyPurchase), { model: 'purchase', lazy: false, asset, tokens: amount(lazyPurchase.tokens, asset.mint.currency) });
};
export const isLazyPurchase = (value) => typeof value === 'object' && value.model === 'purchase' && value.lazy;
export function assertLazyPurchase(value) {
    assert(isLazyPurchase(value), `Expected LazyPurchase type`);
}
export const toLazyPurchase = (account, auctionHouseModel) => {
    return {
        model: 'purchase',
        lazy: true,
        auctionHouse: auctionHouseModel,
        buyerAddress: account.data.buyer,
        sellerAddress: account.data.seller,
        metadataAddress: account.data.metadata,
        bookkeeperAddress: account.data.bookkeeper,
        receiptAddress: account.publicKey,
        price: auctionHouseModel.isNative
            ? lamports(account.data.price)
            : amount(account.data.price, auctionHouseModel.treasuryMint.currency),
        tokens: toBigNumber(account.data.tokenSize),
        createdAt: toDateTime(account.data.createdAt),
    };
};
//# sourceMappingURL=Purchase.js.map