<?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('crm_files', function (Blueprint $table) {
            $table->string('scan_status')->default('clean')->index()->after('checksum');
            $table->text('scan_details')->nullable()->after('scan_status');
            $table->dateTime('scanned_at')->nullable()->after('scan_details');
            $table->string('content_fingerprint', 64)->nullable()->index()->after('scanned_at');
        });
        Schema::create('crm_file_settings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('business_id')->unique();
            $table->unsignedBigInteger('quota_bytes')->default(1073741824);
            $table->string('duplicate_policy')->default('reject');
            $table->unsignedInteger('trash_retention_days')->default(30);
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('crm_file_settings');
        Schema::table('crm_files', fn (Blueprint $table) => $table->dropColumn(['scan_status','scan_details','scanned_at','content_fingerprint']));
    }
};
