<?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::table('attachments', function (Blueprint $table): void {
            $table->decimal('crop_horizontal_start_percent', 7, 4)->nullable()->after('size');
            $table->decimal('crop_vertical_start_percent', 7, 4)->nullable()->after('crop_horizontal_start_percent');
            $table->foreignId('cropped_attachment_id')
                ->nullable()
                ->unique()
                ->after('crop_vertical_start_percent')
                ->constrained('attachments')
                ->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('attachments', function (Blueprint $table): void {
            $table->dropForeign(['cropped_attachment_id']);
            $table->dropColumn([
                'cropped_attachment_id',
                'crop_horizontal_start_percent',
                'crop_vertical_start_percent',
            ]);
        });
    }
};
