<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     * 
     * Adds support for service pricing based on productive hours:
     * - employees_count: Number of employees providing services
     * - hours_per_day: Working hours per day
     * - working_days_per_month: Working days per month
     * - productivity_rate: Percentage of productive time (default 80%)
     * 
     * Formula:
     * Productive Hours = employees × hours/day × days/month × productivity%
     * Fixed Cost/Hour = Fixed Expenses / Productive Hours
     * Service Price = (Fixed Cost/Hour + Service Cost) × Markup
     */
    public function up(): void
    {
        Schema::table('business_settings', function (Blueprint $table) {
            // Service pricing configuration
            $table->enum('business_type', ['products', 'services', 'both'])->default('products')->after('currency');
            
            // Workforce configuration for service pricing
            $table->integer('employees_count')->default(1)->after('business_type');
            $table->decimal('hours_per_day', 4, 2)->default(8.00)->after('employees_count');
            $table->integer('working_days_per_month')->default(22)->after('hours_per_day');
            $table->decimal('productivity_rate', 5, 2)->default(80.00)->after('working_days_per_month');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('business_settings', function (Blueprint $table) {
            $table->dropColumn([
                'business_type',
                'employees_count',
                'hours_per_day',
                'working_days_per_month',
                'productivity_rate',
            ]);
        });
    }
};
