<?php

namespace App\Service\OnChange;

interface OnChangeInterface
{
    /**
     * Validate the new data, throw a RuntimeException if data is not valid
     *
     * @param mixed $data
     * @param OnChangeContext $context
     */
    public function validate(mixed $data, OnChangeContext $context): void;

    /**
     * Apply transformations to the new data before it to be persisted
     *
     * @param mixed $data
     * @param OnChangeContext $context
     * @return mixed
     */
    public function preProcess(mixed $data, OnChangeContext $context): mixed;

    /**
     * Other operations to run before the data to be persisted
     *
     * @param mixed $data
     * @param OnChangeContext $context
     */
    public function beforeChange(mixed $data, OnChangeContext $context): void;

    /**
     * Operations to run after the data has been persisted
     *
     * @param mixed $data
     * @param OnChangeContext $context
     */
    public function onChange(mixed $data, OnChangeContext $context): void;
}
