<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::create('device_schedules', function (Blueprint $table) {
            $table->id();
            $table->foreignId('device_id')->constrained()->cascadeOnDelete();
            $table->boolean('enabled')->default(true);
            // Weekday windows (Mon–Fri)
            $table->string('weekday_green_start_1')->default('06:00');
            $table->string('weekday_green_end_1')->default('10:00');
            $table->string('weekday_green_start_2')->default('16:00');
            $table->string('weekday_green_end_2')->default('20:00');
            // Weekend window (Sat–Sun)
            $table->string('weekend_green_start')->default('10:00');
            $table->string('weekend_green_end')->default('22:00');
            // Re-push interval
            $table->unsignedInteger('repush_hours')->default(6);
            $table->timestamp('last_auto_sent_at')->nullable();
            $table->timestamps();
        });
    }

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