<?php

use App\Models\FeedSchedule;
use Illuminate\Support\Facades\Schedule;
use Illuminate\Support\Facades\Schema;

if (Schema::hasTable('feed_schedules')) {
    $times = FeedSchedule::query()
        ->distinct()
        ->pluck('scheduled_at');

    foreach ($times as $time) {
        $formattedTime = date('H:i', strtotime($time));
        Schedule::command('feed:schedule-process', [$formattedTime])->at($formattedTime);
    }
}

Schedule::command('payroll:generate')->monthlyOn(1, '00:00');
