<?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('daily_plans', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('branch_id')->nullable();
            $table->unsignedBigInteger('user_id')->nullable();     // owner who checks it off
            $table->unsignedBigInteger('assigned_by')->nullable(); // admin who scheduled it
            $table->string('role')->nullable();                    // role-targeted plan (all teachers …)
            $table->string('title');
            $table->text('description')->nullable();
            $table->date('plan_date');
            $table->string('due_time')->nullable();
            $table->string('category')->nullable();                // teaching / meeting / admin / event …
            $table->string('priority')->default('normal');         // low / normal / high / urgent
            $table->string('status')->default('pending');          // pending / done
            $table->timestamp('done_at')->nullable();
            $table->timestamps();
            $table->index(['plan_date', 'user_id']);
            $table->index(['plan_date', 'role']);
        });
    }

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