from datetime import datetime

from sqlalchemy import DateTime, Float, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import BaseModel


class InstanceRealDataSnapshot(BaseModel):
    __tablename__ = "instance_real_data_snapshots"

    instance_id: Mapped[int] = mapped_column(
        ForeignKey("instances.id", ondelete="CASCADE"), nullable=False, index=True
    )
    upstream_id: Mapped[int | None] = mapped_column(Integer, nullable=True, index=True)
    kvm: Mapped[str | None] = mapped_column(String(64), nullable=True)
    cpu_usage: Mapped[float | None] = mapped_column(Float, nullable=True)
    memory_usage: Mapped[float | None] = mapped_column(Float, nullable=True)
    memory_total: Mapped[str | None] = mapped_column(String(64), nullable=True)
    memory_usable: Mapped[str | None] = mapped_column(String(64), nullable=True)
    current_in_bw: Mapped[str | None] = mapped_column(String(64), nullable=True)
    current_out_bw: Mapped[str | None] = mapped_column(String(64), nullable=True)
    current_read_byte: Mapped[float | None] = mapped_column(Float, nullable=True)
    current_write_byte: Mapped[float | None] = mapped_column(Float, nullable=True)
    collected_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, index=True)
    raw_json: Mapped[str | None] = mapped_column(Text, nullable=True)
