/**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $group = $input->getOption('title');
     if (!$group) {
         $output->writeln('<fg=red>You must provide a title for your command</>');
         return;
     }
     $check = WatchlistGroup::where('title', $group)->first();
     if ($check) {
         $output->writeln('<fg=yellow>A group with this name already exists</>');
         return;
     }
     $watchListGroup = new WatchlistGroup();
     $watchListGroup->title = $group;
     $watchListGroup->save();
     $output->writeln('<fg=green>Success! Group with the title of ' . $group . ' created successfully!</>');
 }
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $group = $input->getOption('group');
     $show = $input->getOption('show');
     $link = $input->getOption('link');
     if (!$show && !$link) {
         $output->writeln('<fg=red>You must provide a show ID or link</>');
         return;
     }
     //Let's fetch the ID
     if ($show && !$link) {
         if (!is_numeric($show) || intval($show) != $show || intval($show) <= 0) {
             $output->writeln('<fg=red>Error: Invalid ID</>');
             return;
         } else {
             $showId = intval($show);
         }
     } else {
         $link = $input->getOption('link');
         $url = parse_url($link);
         if (!$url || $url['host'] != 'www.tvmaze.com') {
             $output->writeln('<fg=red>Error: invalid URL</>');
             return;
         }
         preg_match("/\\/shows\\/([0-9]+)\\//i", $url['path'], $matches);
         $showId = $matches[1];
     }
     $check = Watchlist::with('group')->whereHas('group', function ($q) use($group) {
         $q->where('title', $group);
     })->where('tvmaze_id', $showId)->first();
     if ($check) {
         $output->writeln('<fg=red>Error: The show you have provided already exists in the watchlist "' . $check->group->title . '"</>');
         return;
     }
     $groupData = WatchlistGroup::where('title', $group)->first();
     if (!$groupData) {
         $output->writeln('<fg=red>Error: Watchlist group not found</>');
         return;
     }
     $watchlist = new Watchlist();
     $watchlist->watchlist_group_id = $groupData->id;
     $watchlist->tvmaze_id = $showId;
     $watchlist->save();
     $output->writeln('<fg=green>Success: The show is successfully added to watchlist</>');
 }