"""
Organization-level settings for IAM enforcement configuration.

Stores per-org enforcement mode, default policy references,
and feature toggles for the IAM system.
"""

from sqlalchemy import Column, String, DateTime, Boolean, text
from datetime import datetime

from control_plane_api.app.database import Base


class OrganizationSettings(Base):
    """Per-organization settings for IAM enforcement."""

    __tablename__ = "organization_settings"

    organization_id = Column(String(255), primary_key=True)
    enforcement_enabled = Column(Boolean, nullable=False, default=False, server_default=text("false"))
    enforcement_mode = Column(String(50), nullable=False, default="monitoring", server_default=text("'monitoring'"))
    default_policy_id = Column(String(255), nullable=True)
    created_at = Column(DateTime(timezone=False), nullable=True, default=datetime.utcnow, server_default=text("now()"))
    updated_at = Column(DateTime(timezone=False), nullable=True, default=datetime.utcnow, server_default=text("now()"), onupdate=datetime.utcnow)

    __table_args__ = (
        {'schema': 'public'}
    )

    def __repr__(self):
        return f"<OrganizationSettings {self.organization_id} enforcement={self.enforcement_enabled} mode={self.enforcement_mode}>"
