// 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, { autoIndex: false });

    const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
    const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);

    const result = await (await chevre.service.payment.any.createService()).findAuthorizeAction({
        project: {
            id: project.id
        },
        sameAs: {
            id: '6649277cd22032e3e7b6d0fa'
        },
        purpose: {
            id: '66492757d22032e3e7b6d013'
            // id: '66492757d22032e3e7b63'
        }
    })({
        action: actionRepo,
        task: taskRepo
    });
    console.log('result:', result);
}

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