<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Modules\Billing\Enums\ServiceTypeEnum;
use Modules\Core\Enums\AmountTypeEnum;
use Modules\Core\Enums\PriceTypeEnum;
use Modules\Core\Enums\StatusEnum;
use Modules\Core\Enums\VatTypeEnum;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('service_offerings', function (Blueprint $table) {
            $table->id();
            $table->string('name')->index();
            $table->string('service_code')->unique();
            $table->foreignId('service_department_id')->nullable()->constrained('service_departments')->nullOnDelete();
            $table->enum('service_type', ServiceTypeEnum::casesAsArray())->default(ServiceTypeEnum::GENERAL->value)->index();
            $table->foreignId('sales_account_id')->constrained('chart_of_accounts')->restrictOnDelete();
            $table->decimal('base_fee', 20, 6);
            $table->enum('vat_price_type', PriceTypeEnum::casesAsArray())->default(PriceTypeEnum::INCLUSIVE->value);
            $table->enum('vat_type', VatTypeEnum::casesAsArray())->default(VatTypeEnum::STANDARD->value);
            $table->decimal('vat_rate', 5, 2)->default(0);
            $table->enum('subsidy_type', AmountTypeEnum::casesAsArray())->default(AmountTypeEnum::FIXED->value);
            $table->decimal('subsidy_value', 20, 6)->default(0.000000);
            $table->enum('status', StatusEnum::casesAsArray())->index()->default(StatusEnum::ACTIVE);
            $table->timestamps();
            $table->index([
                'vat_type',
                'vat_rate'
            ]);
        });
    }

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