<?php

namespace Database\Seeders;

use App\Models\Loan;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;

class LoanSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Step 1: Delete all files in the attachments folder
        Storage::disk('public')->deleteDirectory('loans');

        // Step 2: Optionally recreate the directory to avoid issues
        Storage::disk('public')->makeDirectory('loans');

        Loan::factory(4)->create();

        foreach (Loan::all() as $loan) {
            $loan->is_valid = true;
            $loan->save();
        }
    }
}
