import { assert } from '../../../utils';
import { amount, lamports, Pda, toBigNumber, toDateTime, toOptionDateTime, } from '../../../types';
/** @group Model Helpers */
export const isListing = (value) => typeof value === 'object' && value.model === 'listing' && !value.lazy;
/** @group Model Helpers */
export function assertListing(value) {
    assert(isListing(value), `Expected Listing type`);
}
/** @group Model Helpers */
export const toListing = (account, auctionHouse, asset) => {
    const lazyListing = toLazyListing(account, auctionHouse);
    return Object.assign(Object.assign({}, lazyListing), { model: 'listing', lazy: false, asset, tokens: amount(lazyListing.tokens, asset.mint.currency) });
};
/** @group Model Helpers */
export const isLazyListing = (value) => typeof value === 'object' && value.model === 'listing' && value.lazy;
/** @group Model Helpers */
export function assertLazyListing(value) {
    assert(isLazyListing(value), `Expected LazyListing type`);
}
/** @group Model Helpers */
export const toLazyListing = (account, auctionHouse) => {
    return {
        model: 'listing',
        lazy: true,
        auctionHouse,
        tradeStateAddress: new Pda(account.data.tradeState, account.data.tradeStateBump),
        bookkeeperAddress: account.data.bookkeeper,
        sellerAddress: account.data.seller,
        metadataAddress: account.data.metadata,
        receiptAddress: new Pda(account.publicKey, account.data.bump),
        purchaseReceiptAddress: account.data.purchaseReceipt,
        // Data.
        price: auctionHouse.isNative
            ? lamports(account.data.price)
            : amount(account.data.price, auctionHouse.treasuryMint.currency),
        tokens: toBigNumber(account.data.tokenSize),
        createdAt: toDateTime(account.data.createdAt),
        canceledAt: toOptionDateTime(account.data.canceledAt),
    };
};
//# sourceMappingURL=Listing.js.map