import type { ScraperAdapter, AdapterConfig, AdapterRunResult, ScraperEnv } from '../types';
import { scrapeCinemall } from '../chains/cinemall';
import { runChainScrape } from '../lib/db-ops';

const adapter: ScraperAdapter = {
  id: 'cinemall',
  async run(config: AdapterConfig, env: ScraperEnv): Promise<AdapterRunResult> {
    const opts = {
      baseUrl: config.base_url as string | undefined,
      homePath: config.home_path as string | undefined,
      cinemaId: config.cinema_id as string | undefined,
      maxMovies: config.max_movies as number | undefined,
    };
    const result = await scrapeCinemall(env, opts);
    return runChainScrape(env, 'cinemall', undefined, result);
  },
};

export default adapter;
