// tslint:disable:no-console
/**
 * イベント集計タスク実行
 */
import { chevre } from '../../../lib/index';

import * as mongoose from 'mongoose';

export async function main() {
    await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });

    const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
    const offerCatalogItemRepo = await chevre.repository.OfferCatalogItem.createInstance(mongoose.connection);

    const result = await offerCatalogRepo.aggregateItemList({ itemListElement: { typeOf: { $eq: chevre.factory.offerType.Offer } } });
    // tslint:disable-next-line:no-null-keyword
    console.dir(result, { depth: null });

    const result2 = await offerCatalogRepo.aggregateItemList({ itemListElement: { typeOf: { $eq: 'OfferCatalog' } } });
    // tslint:disable-next-line:no-null-keyword
    console.dir(result2, { depth: null });

    const result3 = await offerCatalogItemRepo.aggregateItemList({ itemListElement: { typeOf: { $eq: chevre.factory.offerType.Offer } } });
    // tslint:disable-next-line:no-null-keyword
    console.dir(result3, { depth: null });

    const result4 = await offerCatalogItemRepo.aggregateItemList({ itemListElement: { typeOf: { $eq: 'OfferCatalog' } } });
    // tslint:disable-next-line:no-null-keyword
    console.dir(result4, { depth: null });
}

main()
    .then(() => {
        console.log('success!');
    })
    .catch(console.error);
