<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('animals', function (Blueprint $table) {
            $table->decimal('buy_price', 10, 2)->nullable()->change();
            $table->decimal('sale_price', 10, 2)->nullable()->change();
            $table->date('sale_date')->nullable()->change();
        });
    }

    public function down(): void
    {
        DB::table('animals')->whereNull('buy_price')->update(['buy_price' => 0]);
        DB::table('animals')->whereNull('sale_price')->update(['sale_price' => 0]);

        Schema::table('animals', function (Blueprint $table) {
            $table->decimal('buy_price', 10, 2)->default(0)->nullable(false)->change();
            $table->decimal('sale_price', 10, 2)->default(0)->nullable(false)->change();
            $table->date('sale_date')->nullable()->change();
        });
    }
};