<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('ticket_departments', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('description')->nullable();
            $table->boolean('client_only')->default(false);
            $table->boolean('hidden')->default(false);
            $table->boolean('status')->default(true);
            $table->unsignedBigInteger('sla_plan_id')->nullable();

            // Email Settings
            $table->string('outgoing_email_to')->nullable();
            $table->string('outgoing_email_name')->nullable();
            $table->boolean('no_auto_responder')->default(false);
            $table->boolean('have_feedback_request')->default(false);
            $table->integer('feedback_after_hours')->default(24);

            // Mail Import Settings
            $table->string('mail_hostname')->nullable();
            $table->integer('mail_port')->default(993);
            $table->string('mail_email')->nullable();
            $table->string('mail_password')->nullable();
            $table->boolean('mail_import_enabled')->default(false);
            $table->string('mail_protocol', 10)->default('imap');
            $table->boolean('mail_ssl')->default(true);
            $table->text('mail_footer_strip')->nullable();
            $table->integer('mail_poll_interval')->default(5);
            $table->string('mail_post_action', 20)->default('mark_read');
            $table->string('mail_move_folder', 100)->nullable();
            $table->string('mail_auth_type', 20)->default('password');
            $table->boolean('accept_unregistered_emails')->default(false);

            // Slack Integration
            $table->boolean('slack_enabled')->default(false);
            $table->string('slack_channel_prefix', 50)->nullable();

            // Telegram Integration
            $table->boolean('telegram_enabled')->default(false);
            $table->string('telegram_chat_id')->nullable();

            // Discord Integration
            $table->boolean('discord_enabled')->default(false);
            $table->string('discord_webhook_url', 500)->nullable();
            $table->boolean('discord_use_forum_threads')->default(false);

            // Microsoft Teams Integration (PRC-782) — Workflows webhook URL'leri
            // SAS imzalı ve uzun → 1024. teams_use_threads şimdilik rezerve
            // (Teams basit webhook thread desteklemez; şema paritesi için).
            $table->boolean('teams_enabled')->default(false);
            $table->string('teams_webhook_url', 1024)->nullable();
            $table->boolean('teams_use_threads')->default(false);

            // Pushover Integration
            $table->boolean('pushover_enabled')->default(false);
            $table->string('pushover_user_key', 50)->nullable();

            // WhatsApp Integration
            $table->boolean('whatsapp_enabled')->default(false);
            $table->string('whatsapp_phone', 20)->nullable();

            // SMS Integration
            $table->boolean('sms_enabled')->default(false);
            $table->string('sms_notification_phones', 500)->nullable();

            $table->timestamps();
        });
    }

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