import argv from '../src/argv.js';
import { knexOwner as knex } from '../src/knex.js';
import { utilsApi } from '../src/manticore.js';
import { syncManticoreMovies } from '../src/sync.js';

async function init() {
	if (argv.update) {
		await utilsApi.sql('drop table if exists movies');
		await utilsApi.sql(`create table movies (
			 id int,
			 title text,
			 title_filtered text,
			 channel_id int,
			 channel_name text,
			 channel_slug text,
			 network_id int,
			 network_name text,
			 network_slug text,
			 entity_ids multi,
			 actor_ids multi,
			 actors text,
			 tag_ids multi,
			 tags text,
			 meta text,
			 date timestamp,
			 has_cover bool,
			 created_at timestamp,
			 effective_date timestamp,
			 stashed int,
			 stashed_scenes int,
			 stashed_total int,
			 dupe_index int
		)`);

		console.log('Recreated movies tables, syncing movies...');

		const data = await syncManticoreMovies();

		console.log('data', data);
	}

	knex.destroy();
}

init();
