<?php

namespace Modules\MedRegistry\Events;

use Illuminate\Queue\SerializesModels;
use Modules\MedRegistry\Entities\MedregModuleInstance;

/**
 * Fired by ModuleLifecycleService on every instance state change so other
 * modules can react (clear caches, hide menus, stop schedulers, …) without
 * MedRegistry knowing about them.
 *
 * Actions: installed | enabled | disabled | soft_locked | uninstalled
 */
class ModuleInstanceChanged
{
    use SerializesModels;

    /** @var MedregModuleInstance */
    public $instance;

    /** @var string */
    public $action;

    /** Previous status (null when the instance row was just created). */
    public $previousStatus;

    public function __construct(MedregModuleInstance $instance, string $action, ?string $previousStatus = null)
    {
        $this->instance = $instance;
        $this->action = $action;
        $this->previousStatus = $previousStatus;
    }
}
