import { assert, removeEmptyChars } from '../../../utils';
import { Pda, toBigNumber } from '../../../types';
/** @group Model Helpers */
export const isMetadata = (value) => typeof value === 'object' && value.model === 'metadata';
/** @group Model Helpers */
export function assertMetadata(value) {
    assert(isMetadata(value), `Expected Metadata model`);
}
/** @group Model Helpers */
export const toMetadata = (account, json) => {
    var _a;
    return ({
        model: 'metadata',
        address: Pda.find(account.owner, [
            Buffer.from('metadata', 'utf8'),
            account.owner.toBuffer(),
            account.data.mint.toBuffer(),
        ]),
        mintAddress: account.data.mint,
        updateAuthorityAddress: account.data.updateAuthority,
        json: json !== null && json !== void 0 ? json : null,
        jsonLoaded: json !== undefined,
        name: removeEmptyChars(account.data.data.name),
        symbol: removeEmptyChars(account.data.data.symbol),
        uri: removeEmptyChars(account.data.data.uri),
        isMutable: account.data.isMutable,
        primarySaleHappened: account.data.primarySaleHappened,
        sellerFeeBasisPoints: account.data.data.sellerFeeBasisPoints,
        editionNonce: account.data.editionNonce,
        creators: (_a = account.data.data.creators) !== null && _a !== void 0 ? _a : [],
        tokenStandard: account.data.tokenStandard,
        collection: account.data.collection
            ? Object.assign(Object.assign({}, account.data.collection), { address: account.data.collection.key }) : null,
        collectionDetails: account.data.collectionDetails
            ? {
                version: account.data.collectionDetails.__kind,
                size: toBigNumber(account.data.collectionDetails.size),
            }
            : null,
        uses: account.data.uses
            ? Object.assign(Object.assign({}, account.data.uses), { remaining: toBigNumber(account.data.uses.remaining), total: toBigNumber(account.data.uses.total) }) : null,
    });
};
//# sourceMappingURL=Metadata.js.map