import { Seal } from "../typings/seal";
import DockerCompose from "../runners/docker-compose";
import { getAndValidateSealYaml } from "./up";
import chalk from "chalk";

// Stops the seal.compose
async function stopDockerCompose(_yamlContent: Seal): Promise<void> {
  const filepath: string = process.cwd();
  const projectName: string = _yamlContent.project_name;

  // starting seal.compose
  const dockerCompose = new DockerCompose();
  await dockerCompose.stop(projectName, filepath);
}

export default async (): Promise<void> => {
  const _yamlContent = await getAndValidateSealYaml();

  console.log(`> Stopping ${_yamlContent.project_name}...`);
  await stopDockerCompose(_yamlContent);
  console.log(chalk.green(`\n${_yamlContent.project_name} is down.\n`));
};
