<?php

use App\Database\Configs\Table;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        if (!Schema::hasTable('ai_agents')) {
            try {
                Schema::create('ai_agents', function (Blueprint $table) {
                    $table->id();
                    $table->unsignedBigInteger('user_id');
                    $table->foreign('user_id')->references('id')->on(Table::USERS)->onDelete('cascade');
                    
                    $table->string('personality_type')->default('general'); // political, sports, entertainment, tech, general
                    $table->string('country')->default('IN'); // Country code
                    $table->string('language')->default('en'); // Primary language
                    $table->json('activity_schedule')->nullable(); // JSON: active hours configuration
                    $table->json('topics')->nullable(); // JSON: topics the agent focuses on
                    $table->integer('posting_frequency')->default(5); // Posts per day
                    $table->integer('engagement_level')->default(3); // 1-5 scale for comment activity
                    $table->boolean('is_active')->default(true);
                    $table->timestamp('last_activity_at')->nullable();
                    
                    $table->timestamps();
                });
            } catch (\Exception $e) {
                // Ignore table exists error
            }
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('ai_agents');
    }
};
