<?php

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

class CreateClcReminderSettingsTable extends Migration
{
    public function up()
    {
        if (!Schema::hasTable('clc_reminder_settings')) {
            Schema::create('clc_reminder_settings', function (Blueprint $table) {
                $table->increments('id');
                $table->unsignedInteger('business_id');
                $table->boolean('is_enabled')->default(true);
                $table->unsignedTinyInteger('days_before_due')->default(7)
                      ->comment('Send reminder X days before the scheduled vaccine date');
                $table->boolean('send_overdue')->default(true)
                      ->comment('Also send reminders for overdue vaccinations');
                $table->unsignedTinyInteger('overdue_reminder_interval')->default(7)
                      ->comment('Re-send overdue reminder every X days (0 = only once)');
                $table->unsignedTinyInteger('max_reminders_per_vaccine')->default(3)
                      ->comment('Maximum reminder emails per vaccination record');
                $table->boolean('email_enabled')->default(true);
                $table->boolean('wa_enabled')->default(false);
                $table->string('schedule_time', 5)->default('08:00')
                      ->comment('Preferred time to run daily reminders (HH:MM, display only)');
                $table->timestamps();

                $table->unique('business_id');
            });
        }
    }

    public function down()
    {
        Schema::dropIfExists('clc_reminder_settings');
    }
}
