diff --git a/app/Console/Commands/CreateHolidays.php b/app/Console/Commands/CreateHolidays.php new file mode 100644 index 0000000..29e17f7 --- /dev/null +++ b/app/Console/Commands/CreateHolidays.php @@ -0,0 +1,67 @@ +argument('country-code'); + $year = $this->argument('year'); + + if (!is_string($countryCodeStr) || strlen($countryCodeStr) !== 2) { + $this->error('Invalid country code. Must be two-letter code'); + return 1; + } + + if (!is_numeric($year)) { + $this->error('Year must be a numeric value'); + return 1; + } + + $countryCode = strtoupper($countryCodeStr); + $publicHolidaysStore = $publicHolidaysStateFactory->createStoreForCountry($countryCode); + + $this->info('Creating public holidays for country code: ' . $countryCodeStr . ' and year: ' . $year); + + try { + $publicHolidaysGenerator = $publicHolidaysGeneratorFactory->createPublicHolidaysGeneratorForCountry($countryCode); + } catch (\RuntimeException $e) { + $this->error($e->getMessage()); + return 1; + } + + $result = $publicHolidaysGenerator->generatePublicHolidaysForYear((int) $year); + + foreach ($result as $nwdDate) { + $publicHolidaysStore->storePublicHoliday($nwdDate); + } + + $this->info('[DONE] Creating public holidays for country code: ' . $countryCode . ' and year: ' . $year); + + return 0; + } +}