package com.cameleer.server.app.alerting.dto;

import com.cameleer.server.core.alerting.AlertCondition;
import com.cameleer.server.core.alerting.AlertRule;
import com.cameleer.server.core.alerting.AlertRuleTarget;
import com.cameleer.server.core.alerting.AlertSeverity;
import com.cameleer.server.core.alerting.ConditionKind;

import java.time.Instant;
import java.util.List;
import java.util.UUID;

public record AlertRuleResponse(
        UUID id,
        UUID environmentId,
        String name,
        String description,
        AlertSeverity severity,
        boolean enabled,
        ConditionKind conditionKind,
        AlertCondition condition,
        int evaluationIntervalSeconds,
        int forDurationSeconds,
        int reNotifyMinutes,
        String notificationTitleTmpl,
        String notificationMessageTmpl,
        List<WebhookBindingResponse> webhooks,
        List<AlertRuleTarget> targets,
        Instant createdAt,
        String createdBy,
        Instant updatedAt,
        String updatedBy
) {
    public static AlertRuleResponse from(AlertRule r) {
        List<WebhookBindingResponse> webhooks = r.webhooks().stream()
                .map(WebhookBindingResponse::from)
                .toList();
        return new AlertRuleResponse(
                r.id(), r.environmentId(), r.name(), r.description(),
                r.severity(), r.enabled(), r.conditionKind(), r.condition(),
                r.evaluationIntervalSeconds(), r.forDurationSeconds(), r.reNotifyMinutes(),
                r.notificationTitleTmpl(), r.notificationMessageTmpl(),
                webhooks, r.targets(),
                r.createdAt(), r.createdBy(), r.updatedAt(), r.updatedBy());
    }
}
