<?php

namespace SoftminalB2B\Models\Concerns;

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Any write to a model that feeds the precedence walk must invalidate resolved
 * prices. Missing this is the "I changed the rule and nothing happened"
 * staleness complaint that dogs the incumbents.
 */
trait InvalidatesPricing
{
    public function save()
    {
        $result = parent::save();

        if ($result) {
            do_action('smb2b_pricing_data_changed');
        }

        return $result;
    }

    public function delete()
    {
        $result = parent::delete();

        if ($result) {
            do_action('smb2b_pricing_data_changed');
        }

        return $result;
    }

    public static function findByIdAndDelete($id)
    {
        $result = parent::findByIdAndDelete($id);

        if ($result) {
            do_action('smb2b_pricing_data_changed');
        }

        return $result;
    }
}
