<?php

namespace App\Traits;

use App\Services\ArchivableRelationsCascadeService;

trait CascadesArchivableRelations
{
    public static function bootCascadesArchivableRelations(): void
    {
        static::deleting(function ($model) {
            if (!$model->isForceDeleting()) {
                app(ArchivableRelationsCascadeService::class)->softDeleteChildren($model);
            }
        });

        static::restored(function ($model) {
            app(ArchivableRelationsCascadeService::class)->restoreChildren($model);
        });

        static::forceDeleting(function ($model) {
            app(ArchivableRelationsCascadeService::class)->forceDeleteChildren($model);
        });
    }
}
