<?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('strava_connections', function (Blueprint $table) {
            $table->ulid('id')->primary();
            $table->foreignUlid('user_id')->constrained()->cascadeOnDelete();
            $table->unsignedBigInteger('athlete_id')->nullable()->unique();
            $table->text('access_token');
            $table->text('refresh_token');
            $table->timestampTz('expires_at')->nullable()->index();
            $table->json('scopes')->nullable();
            $table->json('athlete')->nullable();
            $table->timestampsTz();

            $table->unique('user_id');
        });
    }

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