<?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('equity_awards', function (Blueprint $table) {
            $table->id();

            $table->foreignId('equity_plan_id')->constrained()->cascadeOnDelete();
            $table->foreignId('employee_id')->constrained()->cascadeOnDelete();
            $table->foreignId('organisation_id')->constrained()->cascadeOnDelete();
            $table->foreignId('appraisal_review_id')->nullable()->constrained()->nullOnDelete();

            $table->decimal('grant_value', 12, 2)->nullable();
            $table->decimal('shares_granted', 12, 2)->nullable();
            $table->decimal('vested_shares', 12, 2)->default(0);

            $table->date('vesting_start_date')->nullable();
            $table->date('vesting_end_date')->nullable();

            $table->enum('status', ['granted', 'vesting', 'vested', 'cancelled'])->default('granted');
            $table->text('notes')->nullable();

            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('equity_awards');
    }
};
