<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('sms_templates', function (Blueprint $table) {
            $table->id();
            $table->string('identifier', 100)->unique();
            $table->string('name', 255);
            $table->text('body')->nullable();
            $table->string('template_id', 100)->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        $now = now();
        DB::table('sms_templates')->insert([
            [
                'identifier' => 'order_placement',
                'name' => 'Order Placement',
                'body' => 'Thanks for your purchase, [[customer_name]]! Your order is processed. View details here: [[invoice_link]] - Kiyo',
                'template_id' => null,
                'is_active' => true,
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'identifier' => 'price_update_alert',
                'name' => 'Price Update Alert',
                'body' => null,
                'template_id' => null,
                'is_active' => true,
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'identifier' => 'login_otp',
                'name' => 'Login OTP',
                'body' => '[[otp]] is your verification code for Kiyo E-commerce.',
                'template_id' => null,
                'is_active' => true,
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'identifier' => 'pos_discount',
                'name' => 'POS / Discount OTP',
                'body' => '[[otp]] is your verification code for discount/transaction.',
                'template_id' => null,
                'is_active' => true,
                'created_at' => $now,
                'updated_at' => $now,
            ],
        ]);
    }

    public function down(): void
    {
        Schema::dropIfExists('sms_templates');
    }
};
