<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * How a destination is laid out, and how long anything stays there.
 *
 * Both per destination, because the two destinations do different jobs. A
 * handover directory that a NAS collects from wants a folder per day and wants
 * emptying — thirty days of folders is enough to notice a NAS that stopped
 * collecting, and keeping more only hides it. The archive on the NAS itself
 * wants a folder per year and wants nothing deleted, ever.
 *
 * Deleting is safe here in a way it usually is not: the invoice lives in the
 * database as a frozen document and the PDF is rendered from it on demand, so
 * anything removed from a directory can be produced again. The directory is a
 * handover point, not the record.
 *
 * keep_days NULL means keep for ever, and that is the default: a retention rule
 * nobody asked for is a deletion nobody expected.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('export_targets', function (Blueprint $table) {
            $table->string('layout', 8)->default('year')->after('path');
            $table->unsignedSmallInteger('keep_days')->nullable()->after('layout');
        });
    }

    public function down(): void
    {
        Schema::table('export_targets', function (Blueprint $table) {
            $table->dropColumn(['layout', 'keep_days']);
        });
    }
};
