<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('corporate_benefits', function (Blueprint $table) {
            $table->id();
            $table->foreignId('corporate_id')->index();
            $table->foreignId('plan_id')->index();
            $table->foreignId('benefit_id')->index();

            $table->string('corporate_benefit_code')->nullable();
            $table->string('budget')->nullable();
            $table->string('budget_conditions')->nullable();
            $table->string('budget_code')->nullable();
            $table->string('primary_benefit_code')->index()->nullable();
            $table->string('benefit_mode')->nullable();
            $table->string('room_class_coverage')->nullable();
            $table->string('max_bed_coverage')->nullable();
            $table->string('tolerance_parameter')->nullable();
            $table->string('max_room_class')->nullable();
            $table->string('limit_amount', 30)->nullable();
            $table->boolean('area_limit')->default(false)->nullable();
            $table->string('shared_benefit')->nullable();
            $table->string('shared_benefit_type')->nullable();
            $table->string('msc')->nullable();
            $table->string('genders')->nullable();
            $table->string('min_age')->nullable();
            $table->string('max_age')->nullable();
            $table->string('max_frequency_period')->nullable();
            $table->string('daily_frequency')->nullable();
            $table->string('weekly_frequency')->nullable();
            $table->string('monthly_frequency')->nullable();
            $table->string('yearly_frequency')->nullable();
            $table->string('custom_frequency_days')->nullable();
            $table->string('custom_duration_value')->nullable();
            $table->string('allowed_transaction_types')->nullable();
            $table->string('high_plan_factor')->nullable();
            $table->boolean('pre_post_treatment')->nullable();
            $table->string('pre_treatment_days')->nullable();
            $table->string('post_treatment_days')->nullable();
            $table->string('layer_type_1')->nullable();
            $table->string('layer_value_1')->nullable();
            $table->string('layer_type_2')->nullable();
            $table->string('layer_value_2')->nullable();
            $table->string('cashless_percentage')->default(100)->nullable();
            $table->string('reimbursement_percentage')->default(100)->nullable();
            $table->string('digital_percentage')->default(100)->nullable();
            $table->string('co_share_m_percentage')->default(100)->nullable();
            $table->string('co_share_s_percentage')->default(100)->nullable();
            $table->string('co_share_c_percentage')->default(100)->nullable();
            $table->string('cashless_deductible', 30)->nullable();
            $table->string('reimbursement_deductible', 30)->nullable();
            $table->string('digital_deductible', 30)->nullable();
            $table->string('co_share_m_deductible', 30)->nullable();
            $table->string('co_share_s_deductible', 30)->nullable();
            $table->string('co_share_c_deductible', 30)->nullable();
            $table->string('prorate_type')->nullable();
            $table->string('prorate_lookup')->nullable();
            $table->string('max_days_for_disability')->nullable();
            $table->string('max_period_for_disability')->nullable();
            $table->string('currency')->nullable();
            $table->string('show_benefit_item')->nullable();
            $table->string('show_benefit_value')->nullable();

            $table->boolean('active')->default(true);

            $table->timestamps();
            $table->softDeletes();
            
            $table->foreignId('created_by')->nullable()->index();
            $table->foreignId('updated_by')->nullable()->index();
            $table->foreignId('deleted_by')->nullable()->index();

            $table->unique(['corporate_id', 'plan_id', 'benefit_id']);
        });
    }

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