<?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('care_messaging_credentials', function (Blueprint $table) {
            $table->id();
            $table->string('owner_ref')->index();
            $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete();
            $table->text('sms_api_key_encrypted')->nullable();
            $table->string('sms_api_key_prefix', 32)->nullable();
            $table->string('sms_sender_id', 11)->nullable();
            $table->string('sms_status', 32)->nullable();
            $table->timestamp('sms_validated_at')->nullable();
            $table->text('sms_last_error')->nullable();
            $table->text('bird_api_key_encrypted')->nullable();
            $table->string('bird_api_key_prefix', 32)->nullable();
            $table->string('bird_from_email')->nullable();
            $table->string('bird_from_name')->nullable();
            $table->string('bird_status', 32)->nullable();
            $table->timestamp('bird_validated_at')->nullable();
            $table->text('bird_last_error')->nullable();
            $table->timestamps();

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

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