<?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
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $exists = DB::table('message_templates')->where('type', 'broadcast')->exists();
        if (!$exists) {
            DB::table('message_templates')->insert([
                'type' => 'broadcast',
                'label' => 'Broadcast ke Semua Pelamar',
                'email_subject' => 'Info Terbaru dari {site_name}',
                'email_body' => 'Halo <strong>{applicant_name}</strong>,<br><br>Kami ingin menginformasikan bahwa ada lowongan pekerjaan terbaru yang mungkin cocok untuk Anda.<br><br>Silakan kunjungi website kami untuk melihat lowongan terbaru:<br><a href="{site_url}">{site_url}</a><br><br>Terima kasih,<br>{site_name}',
                'wa_body' => "Halo {applicant_name},\n\nKami ingin menginformasikan bahwa ada lowongan pekerjaan terbaru yang mungkin cocok untuk Anda.\n\nSilakan kunjungi website kami: {site_url}\n\nTerima kasih,\n{site_name}",
                'available_variables' => json_encode(['applicant_name', 'applicant_email', 'applicant_phone', 'site_name', 'site_url']),
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        DB::table('message_templates')->where('type', 'broadcast')->delete();
    }
};
