from datetime import datetime
from enum import Enum
from typing import Optional

from pydantic import BaseModel


class OrgRole(str, Enum):
    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: Optional[str] = None
    name: str
    slug: str
    is_active: bool = True
    plan: str = "standard"
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None


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


class OrganizationUpdate(BaseModel):
    name: Optional[str] = None
    slug: Optional[str] = None
    is_active: Optional[bool] = None
    plan: Optional[str] = None
