from __future__ import annotations

from enum import Enum
from typing import Any

from pydantic import BaseModel, Field


class MemoryKind(str, Enum):
    PREFERENCE = "preference"
    ENVIRONMENT_FACT = "environment_fact"
    RUNTIME_FACT = "runtime_fact"
    CREDENTIAL_BINDING_FACT = "credential_binding_fact"
    REPAIR_PATTERN = "repair_pattern"


class DurableMemoryRecord(BaseModel):
    kind: MemoryKind
    subject: str = Field(min_length=1)
    value: dict[str, Any] = Field(default_factory=dict)
    source: str = Field(default="armorer")
    verified: bool = Field(default=False)
    created_at: float
    expires_at: float | None = None
    scope: str = Field(default="global")
    tags: list[str] = Field(default_factory=list)

    def is_expired(self, now: float) -> bool:
        return self.expires_at is not None and self.expires_at <= now

