<?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('Config')) {
            Schema::create('Config', function (Blueprint $table) {
                $table->id();
                $table->decimal('RentalTax', 5, 2);
                $table->decimal('RefineRate', 20, 2);
                $table->unsignedBigInteger('RentalTime');
                $table->timestamps();
            });
        }

        if (!Schema::hasTable('eve_mails')) {
            Schema::create('eve_mails', function (Blueprint $table){
                $table->increments('id');
                $table->string('sender');
                $table->string('recipient');
                $table->string('recipient_type');
                $table->text('subject');
                $table->text('body');
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('sent_mails')) {
            Schema::create('sent_mails', function (Blueprint $table) {
                $table->increments('id');
                $table->string('sender');
                $table->string('subject');
                $table->text('body');
                $table->string('recipient');
                $table->string('recipient_type');
            });
        }

        if(!Schema::hasTable('citadels')) {
            Schema::create('citadels', function(Blueprint $table) {
                $table->string('structure_id')->unique();
                $table->string('structure_name');
                $table->string('solar_system_id');
                $table->string('solar_system_name')->nullable();
                $table->string('type_id');
                $table->string('corporation_id');
                $table->boolean('services');
                $table->enum('state', [
                    'anchor_vulnerable',
                    'anchoring',
                    'armor_reinforce',
                    'armor_vulnerable',
                    'deploy_vulnerable',
                    'fitting_invulnerable',
                    'hull_reinforce',
                    'hull_vulnerable',
                    'online_deprecated',
                    'onlining_vulnerable',
                    'shield_vulnerable',
                    'unanchored',
                    'unknown',
                ]);
                $table->dateTime('state_timer_start')->nullable();
                $table->dateTime('state_timer_end')->nullable();
                $table->dateTime('fuel_expires')->nullable();
                $table->string('profile_id');
                $table->string('position_x');
                $table->string('position_y');
                $table->string('position_z');
                $table->dateTime('next_reinforce_apply')->nullable();
                $table->integer('next_reinforce_hour')->nullable();
                $table->integer('next_reinforce_weekday')->nullable();
                $table->integer('reinforce_hour');
                $table->integer('reinforce_weekday')->nullable();
                $table->dateTime('unanchors_at')->nullable();
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('citadel_services')) {
            Schema::create('citadel_services', function(Blueprint $table) {
                $table->increments('id');
                $table->string('structure_id');
                $table->string('name');
                $table->enum('state', [
                    'online',
                    'offline',
                    'cleanup',
                ]);
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('assets')) {
            Schema::create('assets', function(Blueprint $table) {
                $table->increments('id');
                $table->boolean('is_blueprint_copy')->nullable();
                $table->boolean('is_singleton');
                $table->string('item_id');
                $table->enum('location_flag', [
                    'AssetSafety', 
                    'AutoFit', 
                    'Bonus', 
                    'Booster', 
                    'BoosterBay', 
                    'Capsule', 
                    'Cargo', 
                    'CorpDeliveries', 
                    'CorpSAG1', 
                    'CorpSAG2', 
                    'CorpSAG3', 
                    'CorpSAG4', 
                    'CorpSAG5', 
                    'CorpSAG6', 
                    'CorpSAG7', 
                    'CrateLoot', 
                    'Deliveries', 
                    'DroneBay', 
                    'DustBattle', 
                    'DustDatabank', 
                    'FighterBay', 
                    'FighterTube0', 
                    'FighterTube1', 
                    'FighterTube2', 
                    'FighterTube3', 
                    'FighterTube4', 
                    'FleetHangar', 
                    'FrigateEscapeBay', 
                    'Hangar', 
                    'HangarAll', 
                    'HiSlot0', 
                    'HiSlot1', 
                    'HiSlot2', 
                    'HiSlot3', 
                    'HiSlot4', 
                    'HiSlot5', 
                    'HiSlot6', 
                    'HiSlot7', 
                    'HiddenModifiers', 
                    'Implant', 
                    'Impounded', 
                    'JunkyardReprocessed', 
                    'JunkyardTrashed', 
                    'LoSlot0', 
                    'LoSlot1', 
                    'LoSlot2', 
                    'LoSlot3', 
                    'LoSlot4', 
                    'LoSlot5', 
                    'LoSlot6', 
                    'LoSlot7', 
                    'Locked', 
                    'MedSlot0', 
                    'MedSlot1', 
                    'MedSlot2', 
                    'MedSlot3', 
                    'MedSlot4', 
                    'MedSlot5', 
                    'MedSlot6', 
                    'MedSlot7', 
                    'OfficeFolder', 
                    'Pilot', 
                    'PlanetSurface', 
                    'QuafeBay', 
                    'QuantumCoreRoom', 
                    'Reward', 
                    'RigSlot0', 
                    'RigSlot1', 
                    'RigSlot2', 
                    'RigSlot3', 
                    'RigSlot4', 
                    'RigSlot5', 
                    'RigSlot6', 
                    'RigSlot7', 
                    'SecondaryStorage', 
                    'ServiceSlot0', 
                    'ServiceSlot1', 
                    'ServiceSlot2', 
                    'ServiceSlot3', 
                    'ServiceSlot4', 
                    'ServiceSlot5', 
                    'ServiceSlot6', 
                    'ServiceSlot7', 
                    'ShipHangar', 
                    'ShipOffline', 
                    'Skill', 
                    'SkillInTraining', 
                    'SpecializedAmmoHold', 
                    'SpecializedCommandCenterHold', 
                    'SpecializedFuelBay', 
                    'SpecializedGasHold', 
                    'SpecializedIndustrialShipHold', 
                    'SpecializedLargeShipHold', 
                    'SpecializedMaterialBay', 
                    'SpecializedMediumShipHold', 
                    'SpecializedMineralHold', 
                    'SpecializedOreHold', 
                    'SpecializedPlanetaryCommoditiesHold', 
                    'SpecializedSalvageHold', 
                    'SpecializedShipHold', 
                    'SpecializedSmallShipHold', 
                    'StructureActive', 
                    'StructureFuel', 
                    'StructureInactive', 
                    'StructureOffline', 
                    'SubSystemBay', 
                    'SubSystemSlot0', 
                    'SubSystemSlot1', 
                    'SubSystemSlot2', 
                    'SubSystemSlot3', 
                    'SubSystemSlot4', 
                    'SubSystemSlot5', 
                    'SubSystemSlot6', 
                    'SubSystemSlot7', 
                    'Unlocked', 
                    'Wallet', 
                    'Wardrobe',
                ]);
                $table->string('location_id');
                $table->string('location_type');
                $table->integer('quantity');
                $table->string('type_id');
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('wormholes')) {
            Schema::create('wormholes', function (Blueprint $table) {
                $table->increments('id');
                $table->string('system');
                $table->string('sig_id');
                $table->string('duration_left');
                $table->dateTime('dateTime');
                $table->enum('class', [
                    'C1',
                    'C2',
                    'C3',
                    'C4',
                    'C5',
                    'C6',
                    'C7',
                    'C8',
                    'C9',
                    'C13',
                    'Drifter',
                    'Thera',
                    'Exit WH',
                ]);
                $table->string('type');
                $table->enum('hole_size', [
                    'XS',
                    'S',
                    'M',
                    'L',
                    'XL',
                ]);
                $table->enum('stability', [
                    'Stable',
                    'Non-Critical',
                    'Critical',
                ]);
                $table->text('details')->nullable();
                $table->string('link')->nullable();
                $table->unsignedBigInteger('mass_allowed');
                $table->unsignedBigInteger('individual_mass');
                $table->unsignedBigInteger('regeneration');
                $table->enum('stable_time', [
                    '>24 hours',
                    '>4 hours <24 hours',
                    '<4 hours',
                ]);
                $table->timestamps();
            });

            if(!Schema::hasTable('wormhole_types')) {
                Schema::create('wormhole_types', function (Blueprint $table) {
                    $table->increments('id');
                    $table->string('type');
                    $table->string('leads_to');
                    $table->unsignedBigInteger('mass_allowed');
                    $table->unsignedBigInteger('individual_mass');
                    $table->unsignedBigInteger('regeneration');
                    $table->unsignedBigInteger('max_stable_time');
                });
            }
        }

        if(!Schema::hasTable('corporation_wallet_journal')) {
            Schema::create('corporation_wallet_journal', function (Blueprint $table) {
                $table->unsignedBigInteger('id')->unique();
                $table->unsignedBigInteger('corporation_id');
                $table->unsignedInteger('division');
                $table->decimal('amount', 20, 2)->nullable();
                $table->decimal('balance', 20, 2)->nullable();
                $table->unsignedBigInteger('context_id')->nullable();
                $table->enum('context_id_type', [
                    'structure_id',
                    'station_id',
                    'market_transaction_id',
                    'character_id',
                    'corporation_id',
                    'alliance_id',
                    'eve_system',
                    'industry_job_id',
                    'contract_id',
                    'planet_id',
                    'system_id',
                    'type_id',
                ])->nullable();
                $table->dateTime('date')->nullable();
                $table->string('description')->nullable();
                $table->unsignedBigInteger('first_party_id')->nulalble();
                $table->string('reason')->nullable();
                $table->enum('ref_type', [
                    'acceleration_gate_fee',
                    'advertisement_listing_fee',
                    'agent_donation',
                    'agent_location_services',
                    'agent_miscellaneous',
                    'agent_mission_collateral_paid',
                    'agent_mission_collateral_refunded',
                    'agent_mission_reward',
                    'agent_mission_reward_corporation_tax',
                    'agent_mission_time_bonus_reward',
                    'agent_mission_time_bonus_reward_corporation_tax',
                    'agent_security_services',
                    'agent_services_rendered',
                    'agents_preward',
                    'alliance_maintainance_fee',
                    'alliance_registration_fee',
                    'asset_safety_recovery_tax',
                    'bounty',
                    'bounty_prize',
                    'bounty_prize_corporation_tax',
                    'bounty_prizes',
                    'bounty_reimbursement',
                    'bounty_surcharge',
                    'brokers_fee',
                    'clone_activation',
                    'clone_transfer',
                    'contraband_fine',
                    'contract_auction_bid',
                    'contract_auction_bid_corp',
                    'contract_auction_bid_refund',
                    'contract_auction_sold',
                    'contract_brokers_fee',
                    'contract_brokers_fee_corp',
                    'contract_collateral',
                    'contract_collateral_deposited_corp',
                    'contract_collateral_payout',
                    'contract_collateral_refund',
                    'contract_deposit',
                    'contract_deposit_corp',
                    'contract_deposit_refund',
                    'contract_deposit_sales_tax',
                    'contract_price',
                    'contract_price_payment_corp',
                    'contract_reversal',
                    'contract_reward',
                    'contract_reward_deposited',
                    'contract_reward_deposited_corp',
                    'contract_reward_refund',
                    'contract_sales_tax',
                    'copying',
                    'corporate_reward_payout',
                    'corporate_reward_tax',
                    'corporation_account_withdrawal',
                    'corporation_bulk_payment',
                    'corporation_dividend_payment',
                    'corporation_liquidation',
                    'corporation_logo_change_cost',
                    'corporation_payment',
                    'corporation_registration_fee',
                    'courier_mission_escrow',
                    'cspa',
                    'cspaofflinerefund',
                    'datacore_fee',
                    'dna_modification_fee',
                    'docking_fee',
                    'duel_wager_escrow',
                    'duel_wager_payment',
                    'duel_wager_refund',
                    'ess_escrow_transfer',
                    'factory_slot_rental_fee',
                    'gm_cash_transfer',
                    'industry_job_tax',
                    'infrastructure_hub_maintenance',
                    'inheritance',
                    'insurance',
                    'item_trader_payment',
                    'jump_clone_activation_fee',
                    'jump_clone_installation_fee',
                    'kill_right_fee',
                    'lp_store',
                    'manufacturing',
                    'market_escrow',
                    'market_fine_paid',
                    'market_transaction',
                    'medal_creation',
                    'medal_issued',
                    'mission_completion',
                    'mission_cost',
                    'mission_expiration',
                    'mission_reward',
                    'office_rental_fee',
                    'operation_bonus',
                    'opportunity_reward',
                    'planetary_construction',
                    'planetary_export_tax',
                    'planetary_import_tax',
                    'player_donation',
                    'player_trading',
                    'project_discovery_reward',
                    'project_discovery_tax',
                    'reaction',
                    'release_of_impounded_property',
                    'repair_bill',
                    'reprocessing_tax',
                    'researching_material_productivity',
                    'researching_technology',
                    'researching_time_productivity',
                    'resource_wars_reward',
                    'reverse_engineering',
                    'security_processing_fee',
                    'shares',
                    'skill_purchase',
                    'sovereignity_bill',
                    'store_purchase',
                    'store_purchase_refund',
                    'structure_gate_jump',
                    'transaction_tax',
                    'upkeep_adjustment_fee',
                    'war_ally_contract',
                    'war_fee',
                    'war_fee_surrender',
                ]);
                $table->unsignedBigInteger('second_party_id')->nullable();
                $table->decimal('tax', 20, 2)->default(0.00);
                $table->unsignedBigInteger('tax_receiver_id')->nullable();
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('character_assets')) {
            Schema::create('character_assets', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('character_id');
                $table->boolean('is_blueprint_copy');
                $table->boolean('is_singleton');
                $table->unsignedBigInteger('item_id');
                $table->enum('location_flag', [
                    'AssetSafety',
                    'AutoFit',
                    'BoosterBay',
                    'CapsuleerDeliveries',
                    'Cargo',
                    'CorporationGoalDeliveries',
                    'CorpseBay',
                    'Deliveries',
                    'Dronebay',
                    'ExpeditionHold',
                    'FighterBay',
                    'FighterTube0',
                    'FighterTube1',
                    'FighterTube2',
                    'FighterTube3',
                    'FighterTube4',
                    'FleetHangar',
                    'FrigateEscapeBay',
                    'Hangar',
                    'HangarAll',
                    'HiSlot0',
                    'HiSlot1',
                    'HiSlot2',
                    'HiSlot3',
                    'HiSlot4',
                    'HiSlot5',
                    'HiSlot6',
                    'HiSlot7',
                    'HiSlot8',
                    'HiddenModifiers',
                    'Implant',
                    'InfrastructureHangar',
                    'LoSlot0',
                    'LoSlot1',
                    'LoSlot2',
                    'LoSlot3',
                    'LoSlot4',
                    'LoSlot5',
                    'LoSlot6',
                    'LoSlot7',
                    'Locked',
                    'MedSlot0',
                    'MedSlot1',
                    'MedSlot2',
                    'MedSlot3',
                    'MedSlot4',
                    'MedSlot5',
                    'MedSlot6',
                    'MedSlot7',
                    'MobileDepotHold',
                    'MoonMaterialBay',
                    'QuafeBay',
                    'RigSlot0',
                    'RigSlot1',
                    'RigSlot2',
                    'RigSlot3',
                    'RigSlot4',
                    'RigSlot5',
                    'RigSlot6',
                    'RigSlot7',
                    'SpecializedCommandCenterHold',
                    'SpecializedFuelBay',
                    'SpecializedGasHold',
                    'SpecializedIceHold',
                    'SpecializedIndustrialShipHold',
                    'SpecializedLargeShipHold',
                    'SpecializedMaterialBay',
                    'SpecializedMediumShipHold',
                    'SpecializedMineralHold',
                    'SpecializedOreHold',
                    'SpecializedPlanetaryCommoditiesHold',
                    'SpecializedSalvageHold',
                    'SpecializedShipHold',
                    'StructureDeedBay',
                    'SubSystemBay',
                    'SubSystemSlot0',
                    'SubSystemSlot1',
                    'SubSystemSlot2',
                    'SubSystemSlot3',
                    'SubSystemSlot4',
                    'SubSystemSlot5',
                    'SubSystemSlot6',
                    'SubSystemSlot7',
                    'Unlocked',
                    'Wardrobe',
                ]);
                $table->unsignedBigInteger('location_id');
                $table->enum('location_type', [
                    'station',
                    'solar_system',
                    'item',
                    'other',
                ]);
                $table->unsignedBigInteger('quantity');
                $table->unsignedBigInteger('type_id');
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('corporation_assets')) {
            Schema::create('corporation_assets', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('corporation_id');
                $table->boolean('is_blueprint_copy');
                $table->boolean('is_singleton');
                $table->unsignedBigInteger('item_id');
                $table->enum('location_flag', [
                    'AssetSafety',
                    'AutoFit',
                    'BoosterBay',
                    'CapsuleerDeliveries',
                    'Cargo',
                    'CorporationGoalDeliveries',
                    'CorpseBay',
                    'Deliveries',
                    'Dronebay',
                    'ExpeditionHold',
                    'FighterBay',
                    'FighterTube0',
                    'FighterTube1',
                    'FighterTube2',
                    'FighterTube3',
                    'FighterTube4',
                    'FleetHangar',
                    'FrigateEscapeBay',
                    'Hangar',
                    'HangarAll',
                    'HiSlot0',
                    'HiSlot1',
                    'HiSlot2',
                    'HiSlot3',
                    'HiSlot4',
                    'HiSlot5',
                    'HiSlot6',
                    'HiSlot7',
                    'HiSlot8',
                    'HiddenModifiers',
                    'Implant',
                    'InfrastructureHangar',
                    'LoSlot0',
                    'LoSlot1',
                    'LoSlot2',
                    'LoSlot3',
                    'LoSlot4',
                    'LoSlot5',
                    'LoSlot6',
                    'LoSlot7',
                    'Locked',
                    'MedSlot0',
                    'MedSlot1',
                    'MedSlot2',
                    'MedSlot3',
                    'MedSlot4',
                    'MedSlot5',
                    'MedSlot6',
                    'MedSlot7',
                    'MobileDepotHold',
                    'MoonMaterialBay',
                    'QuafeBay',
                    'RigSlot0',
                    'RigSlot1',
                    'RigSlot2',
                    'RigSlot3',
                    'RigSlot4',
                    'RigSlot5',
                    'RigSlot6',
                    'RigSlot7',
                    'SpecializedCommandCenterHold',
                    'SpecializedFuelBay',
                    'SpecializedGasHold',
                    'SpecializedIceHold',
                    'SpecializedIndustrialShipHold',
                    'SpecializedLargeShipHold',
                    'SpecializedMaterialBay',
                    'SpecializedMediumShipHold',
                    'SpecializedMineralHold',
                    'SpecializedOreHold',
                    'SpecializedPlanetaryCommoditiesHold',
                    'SpecializedSalvageHold',
                    'SpecializedShipHold',
                    'StructureDeedBay',
                    'SubSystemBay',
                    'SubSystemSlot0',
                    'SubSystemSlot1',
                    'SubSystemSlot2',
                    'SubSystemSlot3',
                    'SubSystemSlot4',
                    'SubSystemSlot5',
                    'SubSystemSlot6',
                    'SubSystemSlot7',
                    'Unlocked',
                    'Wardrobe',
                ]);
                $table->unsignedBigInteger('location_id');
                $table->enum('location_type', [
                    'station',
                    'solar_system',
                    'item',
                    'other',
                ]);
                $table->unsignedBigInteger('quantity');
                $table->unsignedBigInteger('type_id');
                $table->timestamps();
            });
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('eve_mails');
        Schema::dropIfExists('sent_mail');
        Schema::dropIfExists('citadels');
        Schema::dropIfExists('citadel_services');
        Schema::dropIfExists('assets');
        Schema::dropIfExists('wormholes');
        Schema::dropIfExists('wormhole_types');
        Schema::dropIfExists('corporation_wallet_journal');
        Schema::dropIfExists('character_wallet_journal');
        Schema::dropIfExists('Config');
    }
};
