from datetime import datetime
from typing import List, Optional

from pydantic import Field

from src.apps.base.schemas.common import BaseSchema


class PermissionBase(BaseSchema):
    module: Optional[str] = Field(
        description="Name of the module for which this permission is applicable, inclusive of alphanumeric characters only"
    )
    submodule: Optional[str] = Field(description="Name of the submodule, inclusive of alphanumeric characters only")
    operation: Optional[str] = Field(description="Name of the operation to be performed")
    operation_label: Optional[str] = Field(description="Label of the operation to be performed")
    display_order: Optional[int] = Field(description="Display order of the permission")


class PermissionSchema(PermissionBase):
    id: int = Field(description="Id of permission resource")


# Shared properties
class RoleBase(BaseSchema):
    label: Optional[str] = Field(None, description="Label for the role, inclusive of alphanumeric characters only")
    is_default: Optional[bool] = Field(None, description="Is this role a default role?")


class RoleSchema(RoleBase):
    id: int = Field(description="Id of role resource")
    slug: Optional[str] = Field(None, description="System generated slug for the role")
    created_at: Optional[datetime] = Field(None, description="Created date and time as unix timestamp")
    permissions: Optional[List[PermissionSchema]] = Field(None, description="Permissions associated with this role")


class RoleNoDepsSchema(RoleBase):
    id: int = Field(description="Id of role resource")
    slug: Optional[str] = Field(description="System generated slug for the role")
    created_at: Optional[datetime] = Field(description="Created date and time as unix timestamp")
