import * as core from '@actions/core';
import { Repo, repoString } from './types';
import { main } from './main';

async function run() {
  try {
    // Get input defined in action.yml
    const source_domain = core.getInput('source_repo_domain');
    console.log(`Input SourceDomain received: ${source_domain}`);
    // TODO - check for non-null/empty throughout

    const source_owner = core.getInput('source_repo_owner');
    console.log(`Input Source Owner received: ${source_owner}`);

    const source_name = core.getInput('source_repo_name');
    console.log(`Input SourceName received: ${source_name}`);
    
    const target_domain = core.getInput('target_repo_domain');
    console.log(`Input Target Domain received: ${target_domain}`);

    const target_owner = core.getInput('target_repo_owner');
    console.log(`Input Target Owner received: ${target_owner}`);

    const target_name = core.getInput('target_repo_name');
    console.log(`Input Target Name received: ${target_name}`);

    const dry_run_inp = core.getInput('dry_run');
    // TODO - check how this looks when called from the 
    console.log(`Input DryRun received: ${dry_run_inp}`);
    // This, rather than the more-natural `== 'true'`, because I don't know what form the input will be in (`TRUE`,
    // `YES`, `1`, etc. or indeed if it can even be `required`), and I want to default to `dry_run` the first time I run
    // this to avoid accidentally triggering a ton of commits before I get a chance to observe output.
    const dry_run = !(dry_run_inp == 'false');
    
    const token_for_target_repo = core.getInput('token_for_target_repo');
    // Obviously, don't log this!


    await main({domain:source_domain, owner:source_owner, name:source_name}, {domain:target_domain, owner:target_owner, name:target_name}, dry_run, token_for_target_repo);

  } catch (error) {
    if (error instanceof Error) {
      core.setFailed(error.message);
    }
  }
}

run(); 