// tslint:disable:no-console
import * as mongoose from 'mongoose';

import { chevre } from '../../../lib/index';

const project = { id: String(process.env.PROJECT_ID) };

async function main() {
    await mongoose.connect(<string>process.env.MONGOLAB_URI);

    const sellerRepo = await chevre.repository.Seller.createInstance(mongoose.connection);

    const sellersByAggregate = await sellerRepo.searchByAggregate(
        {
            limit: 10,
            page: 1,
            sort: { branchCode: chevre.factory.sortType.Descending },
            // id: { $eq: '59d20831e53ebc2b4e774466' }
            project: { id: { $eq: project.id } }
            // paymentAccepted: { paymentMethodType: { $eq: 'Cash' } },
            // hasMerchantReturnPolicy: { applicablePaymentMethod: {} }
        },
        ['additionalProperty', 'project', 'name', 'typeOf', 'url', 'telephone']
    );
    // tslint:disable-next-line:no-null-keyword
    console.dir(sellersByAggregate, { depth: null });
    console.log('sellers found', sellersByAggregate, sellersByAggregate[0]?.hasMerchantReturnPolicy);
    console.log(sellersByAggregate.length, 'sellers found');
}

main()
    .then()
    .catch(console.error);
