<?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('sales_targets', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('title')->nullable();          // مثلاً هدف تیر ۱۴۰۵
            $table->decimal('target_amount', 15, 2)->default(0);  // مبلغ فروش هدف
            $table->unsignedInteger('target_deals')->default(0);  // تعداد قرارداد هدف
            $table->date('starts_at');
            $table->date('ends_at');
            $table->timestamps();

            $table->index(['user_id', 'starts_at', 'ends_at']);
        });
    }

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