// 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 categoryCodeRepo = await chevre.repository.CategoryCode.createInstance(mongoose.connection);
    const coaAuthClient = new (await chevre.loadCOA()).auth.RefreshToken({
        endpoint: '',
        refreshToken: '',
        useFetch: true
    });
    const masterService = new (await chevre.loadCOA()).service.Master(
        {
            endpoint: '',
            auth: coaAuthClient
        },
        { timeout: 20000 }
    );

    await (await chevre.service.offer.createService()).event.importCategoryCodesFromCOA({
        project,
        theaterCode: '120'
    })({ categoryCode: categoryCodeRepo, masterService });
    console.log('imported');
}

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