<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('cron_task_types', function (Blueprint $table) {
            $table->string('slug')->primary();
            $table->timestamps();
        });


        Schema::create('cron_tasks', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->string('execution_type');
            $table->time('schedule_time')->nullable();
            $table->json('last_run')->nullable();
            $table->timestamps();

            $table->foreign('execution_type')->references('slug')->on('cron_task_types')->cascadeOnDelete()->cascadeOnUpdate();

        });
    }

    public function down(): void
    {
        Schema::dropIfExists('cron_tasks');
        Schema::dropIfExists('cron_task_types');
    }
};
