// database/migrations/xxxx_create_courier_salaries_table.php
<?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('courier_salaries', function (Blueprint $table) {
            $table->id();
            $table->foreignId('courier_id')->constrained('users')->onDelete('cascade');
            $table->integer('month');        // 1–12
            $table->integer('year');
            $table->integer('total_deliveries')->default(0); // jumlah antar bulan ini
            $table->bigInteger('base_salary')->default(0);   // gaji pokok
            $table->bigInteger('bonus')->default(0);         // bonus per pengiriman
            $table->bigInteger('total_salary')->default(0);  // total = base + bonus
            $table->enum('status', ['unpaid', 'paid'])->default('unpaid');
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();

            $table->unique(['courier_id', 'month', 'year']); // 1 record per kurir per bulan
        });
    }

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