<?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('members', function (Blueprint $t) {
            $t->id(); $t->foreignId('organization_id')->constrained()->cascadeOnDelete();
            $t->string('full_name'); $t->string('nickname')->nullable(); $t->string('title_prefix')->nullable(); $t->string('title_suffix')->nullable();
            $t->string('position'); $t->string('whatsapp',40)->nullable(); $t->string('email')->nullable(); $t->text('address')->nullable();
            $t->string('photo_path')->nullable(); $t->string('sk_number')->nullable(); $t->date('period_start')->nullable(); $t->date('period_end')->nullable();
            $t->boolean('is_active')->default(true); $t->timestamps(); $t->index(['organization_id','is_active']);
        });
        Schema::create('programs', function (Blueprint $t) {
            $t->id(); $t->foreignId('organization_id')->constrained()->cascadeOnDelete(); $t->string('name'); $t->string('category')->nullable();
            $t->foreignId('pic_member_id')->nullable()->constrained('members')->nullOnDelete(); $t->string('target')->nullable();
            $t->date('start_date')->nullable(); $t->date('due_date')->nullable(); $t->decimal('budget',15,2)->default(0); $t->decimal('realization',15,2)->default(0);
            $t->unsignedTinyInteger('progress')->default(0); $t->string('status',30)->default('not_started'); $t->boolean('public_visible')->default(true);
            $t->boolean('aggregate_to_main')->default(true); $t->text('notes')->nullable(); $t->timestamps();
        });
        Schema::create('activities', function (Blueprint $t) {
            $t->id(); $t->foreignId('organization_id')->constrained()->cascadeOnDelete(); $t->string('title'); $t->string('type',80)->nullable();
            $t->text('description')->nullable(); $t->dateTime('start_at')->nullable(); $t->dateTime('end_at')->nullable(); $t->string('location')->nullable();
            $t->decimal('latitude',10,7)->nullable(); $t->decimal('longitude',10,7)->nullable(); $t->unsignedInteger('participants_count')->default(0);
            $t->decimal('budget',15,2)->default(0); $t->longText('report')->nullable(); $t->string('featured_image')->nullable();
            $t->string('status',30)->default('planned'); $t->boolean('public_visible')->default(true); $t->boolean('aggregate_to_main')->default(true); $t->timestamps();
        });
    }
    public function down(): void { Schema::dropIfExists('activities'); Schema::dropIfExists('programs'); Schema::dropIfExists('members'); }
};
