<?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('upwork_sync_logs', function (Blueprint $table) {
            $table->id();
            $table->enum('status', ['success', 'error', 'partial'])->default('success');
            $table->integer('contracts_fetched')->default(0);
            $table->integer('sales_created')->default(0);
            $table->integer('sales_updated')->default(0);
            $table->text('error_message')->nullable();
            $table->json('raw_summary')->nullable();
            $table->timestamp('synced_at');
            $table->timestamps();

            $table->index('status');
            $table->index('synced_at');
        });
    }

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