package com.cameleer.server.core.alerting;

import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;

class AlertDomainRecordsTest {

    @Test
    void alertRuleDefensiveCopy() {
        var webhooks = new java.util.ArrayList<WebhookBinding>();
        webhooks.add(new WebhookBinding(UUID.randomUUID(), UUID.randomUUID(), null, null));
        var r = newRule(webhooks);
        webhooks.clear();
        assertThat(r.webhooks()).hasSize(1);
    }

    @Test
    void silenceMatcherAllFieldsNullMatchesEverything() {
        var m = new SilenceMatcher(null, null, null, null, null);
        assertThat(m.isWildcard()).isTrue();
    }

    private AlertRule newRule(List<WebhookBinding> wh) {
        return new AlertRule(
            UUID.randomUUID(), UUID.randomUUID(), "r", null,
            AlertSeverity.WARNING, true, ConditionKind.AGENT_STATE,
            new AgentStateCondition(new AlertScope(null,null,null), "DEAD", 60),
            60, 0, 60, "t", "m", wh, List.of(),
            Instant.now(), null, null, Map.of(),
            Instant.now(), "u1", Instant.now(), "u1");
    }
}
