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

async function init() {
	if (argv.update) {
		await utilsApi.sql('drop table if exists scenes');
		await utilsApi.sql(`create table scenes (
			 id int,
			 title text,
			 title_filtered text,
			 entry_id text,
			 shoot_id text,
			 channel_id int,
			 channel_name text,
			 channel_slug text,
			 network_id int,
			 network_name text,
			 network_slug text,
			 studio_id int,
			 studio_name text,
			 studio_slug text,
			 entity_ids multi,
			 actor_ids multi,
			 actors text,
			 tag_ids multi,
			 assigned_tag_ids multi64,
			 tags text,
			 movie_ids multi,
			 movies text,
			 serie_ids multi,
			 series text,
			 meta text,
			 date timestamp,
			 fingerprints text,
			 is_showcased bool,
			 created_at timestamp,
			 effective_date timestamp,
			 stashed int,
			 dupe_index int
		)`);

		await utilsApi.sql('drop table if exists scenes_tags');

		/* legacy, using packed decimal keys now
		await utilsApi.sql(`create table scenes_tags (
			 id int,
			 scene_id int,
			 tag_id int,
			 actor_id int
		)`);
		*/

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

		await syncManticoreScenes();
	}

	knex.destroy();
}

init();
