<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use MtcPharmacy\Subscriptions\Classes\Subscription;

class AddIntervalFieldsToSubscriptionPreferences extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('subscription_preferences', function (Blueprint $table) {
            if (!Schema::hasColumn('subscription_preferences', 'interval')) {
                $table->enum('interval', Subscription::get_allowed_intervals())->default(Subscription::INTERVAL_MONTHS)->after('max_number_of_issues');
            }
            if (!Schema::hasColumn('subscription_preferences', 'interval_multiplier')) {
                $table->integer('interval_multiplier')->default(1)->after('max_number_of_issues');
            }
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('subscription_preferences', function(Blueprint $table) {
            $table->dropColumn('interval');
            $table->dropColumn('interval_multiplier');
        });
    }
}


