<?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()
    {
        // Coupon table
        Schema::table('coupons', function (Blueprint $table) {
            $table->dropColumn('current_usage');
            $table->dropColumn('monthly_percentage');
            $table->dropColumn('yearly_percentage');
            $table->renameColumn('expiration_date', 'validity_date');
            $table->renameColumn('amount', 'discount');
            $table->enum('type', ['fixed', 'percentage'])->default('fixed');
            $table->integer('range')->default(0);
        });

        // Company Subscription
        Schema::table('company_subscription_payments', function (Blueprint $table) {
            $table->bigInteger('coupon_id')->index();
            $table->float('coupon_discount');
            $table->float('total_discounted_amount');
        });

        // Company Subscription
        Schema::table('company_subscriptions', function (Blueprint $table) {
            $table->boolean('used_coupon')->default(false)->comment = 'Applicable only on monthly payment. Used to check if already used a coupon discount';;
            $table->float('coupon_discount');
            $table->float('total_discounted_amount');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        // Coupon table
        Schema::table('coupons', function (Blueprint $table) {
            $table->double('monthly_percentage', 10, 2)->nullable();
            $table->double('yearly_percentage', 10, 2)->nullable();
            $table->integer('current_usage')->default(0);
            $table->renameColumn('validity_date', 'expiration_date');
            $table->renameColumn('discount', 'amount');
            $table->dropColumn('type');
            $table->dropColumn('range');
        });

        // Company Subscription Payments
        Schema::table('company_subscription_payments', function (Blueprint $table) {
            $table->dropColumn('coupon_id');
            $table->dropColumn('coupon_discount');
            $table->dropColumn('total_discounted_amount');
        });

         // Company Subscription
         Schema::table('company_subscriptions', function (Blueprint $table) {
            $table->dropColumn('used_coupon');
            $table->dropColumn('coupon_discount');
            $table->dropColumn('total_discounted_amount');
        });


    }
};
