from datetime import datetime
from enum import StrEnum

from pydantic import BaseModel


class OrgRole(StrEnum):
    OWNER = "owner"
    ADMIN = "admin"
    MANAGER = "manager"
    MEMBER = "member"
    VIEWER = "viewer"

    @classmethod
    def _ordering(cls) -> list:
        return [cls.VIEWER, cls.MEMBER, cls.MANAGER, cls.ADMIN, cls.OWNER]

    def __ge__(self, other: "OrgRole") -> bool:
        return self._ordering().index(self) >= self._ordering().index(other)

    def __gt__(self, other: "OrgRole") -> bool:
        return self._ordering().index(self) > self._ordering().index(other)

    def __le__(self, other: "OrgRole") -> bool:
        return self._ordering().index(self) <= self._ordering().index(other)

    def __lt__(self, other: "OrgRole") -> bool:
        return self._ordering().index(self) < self._ordering().index(other)


class Organization(BaseModel):
    id: str | None = None
    name: str
    slug: str
    is_active: bool = True
    plan: str = "standard"
    created_at: datetime | None = None
    updated_at: datetime | None = None


class OrganizationCreate(BaseModel):
    name: str
    slug: str


class OrganizationUpdate(BaseModel):
    name: str | None = None
    slug: str | None = None
    is_active: bool | None = None
    plan: str | None = None
