from django.forms import model_to_dict


def to_correlator_data(rule):
    return {
        "name": rule.name,
        "depth": str(int(rule.depth.total_seconds())) + "s",
        "id": str(rule.pk),
        "predicat": rule.rule_json,
        "actions": rule.actions_json,
        "multi": rule.multi
    }


def check_if_only_status_changed(rule):
    initial_data = getattr(rule, '_initial', {})
    new_data = model_to_dict(rule, fields=[field.name for field in rule._meta.fields])
    diffs = [k for k, v in initial_data.items() if v != new_data[k]]
    return len(diffs) == 1 and 'status' in diffs
