<?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
    {
        if(!Schema::hasTable('moon_mining_tax')) {
            Schema::create('moon_mining_tax', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('moon_id');
                $table->string('name');
                $table->unsignedBigInteger('character_id');
                $table->string('character_name');
                $table->decimal('worth', 20, 2);
                $table->decimal('tax_bracket', 5, 2);
                $table->decimal('tax_amount', 20, 2);
                $table->dateTime('rental_end');
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('ore_mining_tax')) {
            Schema::create('ore_mining_tax', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('character_id');
                $table->string('character_name');
                $table->unsignedBigInteger('corporation_id');
                $table->string('corporation_name');
                $table->unsignedBigInteger('ore_id');
                $table->string('ore');
                $table->unsignedBigInteger('ore_amount');
                $table->decimal('ore_worth', 20, 2);
                $table->decimal('tax_amount', 20, 2);
                $table->dateTime('tax_date');
                $table->timestamps();
            });
        }
        
        if(!Schema::hasTable('mining_tax')) {
            Schema::create('mining_tax', function (Blueprint $table) {
                $table->id();
                $table->string('character_id');
                $table->string('character_name');
                $table->dateTime('month_end');
                $table->decimal('amount', 20, 2);
            });
        }
    }

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