<?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
    {
        Schema::create('audits', function (Blueprint $table) {
            $table->id();

            //* Basic Data

                // Of Creation
                $table->date('audit_date');                                 // Date audit performed
                $table->time('audit_time', 0);                              // Time audit performed

                $table->unsignedBigInteger('receptionist_id')               // Receptionist assigned to the count
                    ->nullable()->default(1);
                $table->foreign('receptionist_id')
                    ->references('id')->on('users')
                    ->onDelete('set null');

                $table->unsignedBigInteger('shift_id')->nullable();         // Work shift in progress
                $table->foreign('shift_id')
                    ->references('id')->on('shifts')
                    ->onDelete('set null');

                // Incomes
                $table->decimal('theoretical_lodging_income', 10, 2);       // Suspected lodging income
                $table->json('summary_lodging_revenues');                   // Summary of total lodging revenues, separated by each payment method recorded in the system
                $table->decimal('real_lodging_income', 10, 2);              // Actual lodging income earned

                $table->decimal('theoretical_consumption_income', 10, 2);   // Suspected consumption income
                $table->json('summary_consumption_revenues');               // Summary of total consumption revenues, separated by each payment method recorded in the system
                $table->decimal('real_consumption_income', 10, 2);          // Actual consumption income earned

                $table->decimal('theoretical_extra_income', 10, 2);         // Suspected extra income
                $table->json('summary_extra_revenues');                     // Summary of total extra revenues, separated by each payment method recorded in the system
                $table->decimal('real_extra_income', 10, 2);                // Actual extra income earned

                $table->decimal('theoretical_restaurant_income', 10, 2)     // Suspected restaurant income
                    ->default(0.0);
                $table->json('summary_restaurant_revenues')->nullable();    // Summary of total restaurant revenues, separated by each payment method recorded in the system
                $table->decimal('real_restaurant_income', 10, 2)            // Actual restaurant income earned
                    ->default(0.0);

                $table->decimal('theoretical_mini_shop_income', 10, 2)      // Suspected mini shop income
                    ->default(0.0);
                $table->json('summary_mini_shop_revenues')->nullable();     // Summary of total mini shop revenues, separated by each payment method recorded in the system
                $table->decimal('real_mini_shop_income', 10, 2)             // Actual mini shop income earned
                    ->default(0.0);

                // Global Summaries
                $table->json('income_confirmation_summary');                // Summary of final counts for each of the system's payment methods
                $table->json('petty_cash_summary')->nullable();             // Summary of final count for internal Petty Cash (just informative control)

            //* Control Data
                $table->boolean('is_concluded')->default(0);                // has the audit been concluded by the receptionist on duty?
                $table->boolean('is_approved')->default(0);                 // Is the audit approved by the next receptionist on duty?

                $table->text('rejection_reason')->nullable();                // Reason for disapprove the audit counting
                $table->string('auditor')->nullable();                       // Receptionist who audited the shift

            $table->timestamps();
        });
    }

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