<?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('plans', function (Blueprint $table) {
            $table->id();
            $table->string('service_code')->index();
            $table->string('corporate_id')->index();
            $table->string('corporate_plan_id')->index();
            $table->string('code')->index();
            $table->string('type')->nullable();
            $table->dateTime('start')->nullable();
            $table->dateTime('end')->nullable();
            $table->string('require_referral')->nullable();
            $table->string('referral_source')->nullable();
            $table->string('referral_duration')->nullable();
            $table->string('family_plan')->nullable();
            $table->string('family_plan_share_rules')->nullable();
            $table->string('limit_rules')->nullable(); // Annual Limit
            $table->string('layer')->nullable();
            $table->string('layer_conditions')->nullable();
            $table->string('budget_type')->nullable();
            $table->string('budget_code')->nullable();
            $table->string('budget_conditions')->nullable();
            $table->string('surgery_limit', 30)->nullable();
            $table->string('non_surgery_limit', 30)->nullable();
            $table->string('max_claim_limit', 30)->nullable();
            $table->integer('max_claim_count')->nullable();
            $table->boolean('area_limit')->nullable();
            $table->string('limit_shared_plans')->nullable();
            $table->string('limit_shared_plan_type')->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('co_share_deductible_condition')->nullable();
            $table->string('msc')->nullable();
            $table->string('genders')->nullable();
            $table->string('min_age')->nullable();
            $table->string('max_age')->nullable();
            $table->string('rule_of_excess')->nullable();
            $table->string('max_excess_covered')->nullable();
            $table->string('prorate_type')->nullable();
            $table->string('prorate_lookup')->nullable();
            $table->string('currency')->nullable();
            $table->float('max_surgery_reinstatement_days')->nullable();
            $table->float('max_surgery_periode_days')->nullable();
            

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

            $table->index(['corporate_id', 'code']);
        });
    }

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