<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::dropIfExists('jumlah_buku');
    }

    public function down(): void
    {
        Schema::create('jumlah_buku', function ($table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->string('kod_sekolah', 20)->nullable();
            $table->year('tahun')->nullable();
            $table->string('kod_buku', 20);
            $table->integer('jumlah')->default(0);
            $table->integer('unjuran_enrolmen')->default(0);
            $table->integer('baki_buku_boss')->default(0);
            $table->integer('buku_elok_boss')->default(0);
            $table->integer('anggaran_buku_elok_tangan')->default(0);
            $table->integer('stok_hingga_akhir')->default(0);
            $table->integer('elok_hingga_akhir')->default(0);
            $table->integer('pesan_tahun')->default(0);
            $table->timestamps();
            $table->unique(['user_id', 'tahun', 'kod_buku'], 'jumlah_buku_user_tahun_kod_unique');
        });
    }
};
