<?php

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
    {
        Schema::create('call_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->bigInteger('local_id')->nullable(); // ID from Android app
            $table->string('phone_number');
            $table->enum('call_type', ['INCOMING', 'MISSED', 'OUTGOING', 'REJECTED']);
            $table->timestamp('call_time');
            $table->integer('call_duration')->default(0); // Duration in seconds
            $table->boolean('sms_sent')->default(false);
            $table->timestamps();

            $table->index('phone_number');
            $table->index('call_time');
            $table->index('call_type');
            $table->index(['user_id', 'call_time']);
        });
    }

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