package com.hiveops.aria.entity;

import jakarta.persistence.*;
import lombok.*;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.UUID;

@Entity
@Table(name = "precursor_sequence_alert")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PrecursorSequenceAlert {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "device_id")
    private Long deviceId;

    @Column(name = "device_agent_id")
    private String deviceAgentId;

    @Enumerated(EnumType.STRING)
    @Column(name = "sequence_type", nullable = false, columnDefinition = "sequence_type")
    @Builder.Default
    private SequenceType sequenceType = SequenceType.JACKPOTTING;

    @Column(name = "phases_detected", columnDefinition = "attack_phase[]")
    private String[] phasesDetected;

    @Column(nullable = false, precision = 4, scale = 3)
    @Builder.Default
    private BigDecimal confidence = BigDecimal.ZERO;

    @Column(name = "triggered_at", nullable = false)
    @Builder.Default
    private Instant triggeredAt = Instant.now();

    @Enumerated(EnumType.STRING)
    @Column(name = "auto_response_taken", nullable = false, columnDefinition = "auto_response_action")
    @Builder.Default
    private AutoResponseAction autoResponseTaken = AutoResponseAction.NONE;

    @Column(name = "resolved_at")
    private Instant resolvedAt;

    @Column(name = "resolved_by")
    private String resolvedBy;

    @Column(name = "institution_key")
    private String institutionKey;

    @Column(name = "sequence_id", nullable = false)
    @Builder.Default
    private UUID sequenceId = UUID.randomUUID();

    public enum SequenceType {
        JACKPOTTING, SKIMMING, UNKNOWN
    }

    public enum AutoResponseAction {
        NONE, SHUTDOWN, NOTIFICATION, LOCKDOWN
    }
}
