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

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

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

// tslint:disable-next-line:max-func-body-length
async function main() {
    await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });

    const aggregateOfferRepo = await chevre.repository.AggregateOffer.createInstance(mongoose.connection);

    await aggregateOfferRepo.pushIncludedInDataCatalog({
        project: {
            id: project.id
        },
        id: {
            $in: ['1001']
        },
        $push: {
            includedInDataCatalog: {
                $each: [{ id: '0001' }]
            }
        }
    });
    console.log('pushed');

    // const pullResult = await aggregateOfferRepo.pullIncludedInDataCatalog({
    //     project: {
    //         id: project.id
    //     },
    //     id: {
    //         // $nin: ['1001']
    //     },
    //     $pull: {
    //         includedInDataCatalog: {
    //             $elemMatch: { id: { $eq: '0001' } }
    //         }
    //     }
    // });
    // console.log('pulled', pullResult);
}

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