// tslint:disable:no-console
import * as moment from 'moment';
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 eventSeriesRepo = await chevre.repository.EventSeries.createInstance(mongoose.connection);

    const result = await eventSeriesRepo.upsertByVersion(
        [
            {
                $set: {
                    eventStatus: chevre.factory.eventStatusType.EventScheduled,
                    videoFormat: [],
                    soundFormat: [],
                    kanaName: '',
                    startDate: moment('2023-12-08T15:00:00Z')
                        .toDate(),
                    endDate: moment('2123-12-08T15:00:00Z')
                        .toDate(),
                    typeOf: chevre.factory.eventType.ScreeningEventSeries,
                    duration: 'PT2H',
                    name: { ja: '名探偵コナン ゼロの執行人', en: 'Detective Conan Zero Enforcer' },
                    offers: {
                        typeOf: chevre.factory.offerType.Offer
                    },
                    project: { typeOf: chevre.factory.organizationType.Project, id: PROJECT_ID },
                    additionalProperty: [
                    ],
                    location: {
                        branchCode: '118',
                        id: '5bfb841d5a78d7948369979a',
                        name: { ja: 'シネモーション赤坂 ', en: 'CineMotion Akasaka' },
                        typeOf: chevre.factory.placeType.MovieTheater
                    },
                    workPerformed: {
                        typeOf: chevre.factory.creativeWorkType.Movie,
                        id: '5bfb841d5a78d79483699801',
                        identifier: '071953',
                        name: {
                            ja: '男はつらいよ 純情篇'
                        },
                        duration: 'PT1H29M',
                        version: '2'
                    },
                    organizer: { id: '59d20831e53ebc2b4e774466' },
                    headline: { ja: 'xxx', en: '' }
                },
                $unset: {}
            },
            {
                $set: {
                    eventStatus: chevre.factory.eventStatusType.EventScheduled,
                    videoFormat: [],
                    soundFormat: [],
                    kanaName: '',
                    startDate: moment('2023-12-08T15:00:00Z')
                        .toDate(),
                    endDate: moment('2123-12-08T15:00:00Z')
                        .toDate(),
                    typeOf: chevre.factory.eventType.ScreeningEventSeries,
                    duration: 'PT2H',
                    name: { ja: '名探偵コナン ゼロの執行人', en: 'Detective Conan Zero Enforcer' },
                    offers: {
                        typeOf: chevre.factory.offerType.Offer
                    },
                    project: { typeOf: chevre.factory.organizationType.Project, id: PROJECT_ID },
                    additionalProperty: [
                    ],
                    location: {
                        branchCode: '118',
                        id: '5bfb841d5a78d7948369979a',
                        name: { ja: 'シネモーション赤坂 ', en: 'CineMotion Akasaka' },
                        typeOf: chevre.factory.placeType.MovieTheater
                    },
                    workPerformed: {
                        typeOf: chevre.factory.creativeWorkType.Movie,
                        id: '5bfb841d5a78d79483699801',
                        identifier: '071953',
                        name: {
                            ja: '男はつらいよ 純情篇'
                        },
                        duration: 'PT1H29M',
                        version: '6'
                    },
                    organizer: { id: '59d20831e53ebc2b4e774466' }
                }
            }
        ]
    );
    console.log('result:', result);
}

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