// 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 offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);

    const result = await offerCatalogRepo.upsertManyByIdentifier(
        [
            {
                $set: {
                    project: { typeOf: chevre.factory.organizationType.Project, id: PROJECT_ID },
                    typeOf: 'OfferCatalog',
                    id: '',
                    identifier: '2023121501',
                    itemListElement: [
                        { id: '1001', typeOf: chevre.factory.offerType.Offer }
                    ],
                    itemOffered: { typeOf: chevre.factory.product.ProductType.EventService },
                    name: {
                        en: '2023121501',
                        ja: '2023121501'
                    },
                    description: {
                        en: '2023121501',
                        ja: '2023121501'
                    },
                    additionalProperty: []
                },
                $unset: {}
            }
        ]
        // { replace: true }
    );
    console.log('result:', result);
}

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