from datetime import datetime

from pydantic import BaseModel, EmailStr

from .organization import OrgRole


class Invitation(BaseModel):
    id: str | None = None
    email: str
    organization_id: str
    role_in_org: OrgRole
    target_team_ids: list[str] = []
    token_hash: str
    invited_by_user_id: str
    expires_at: datetime
    accepted_at: datetime | None = None
    revoked_at: datetime | None = None
    created_at: datetime | None = None


class InvitationCreate(BaseModel):
    email: EmailStr
    role_in_org: OrgRole = OrgRole.MEMBER
    target_team_ids: list[str] = []
    expires_in_days: int = 7


class InvitationPreviewResponse(BaseModel):
    org_name: str
    org_slug: str
    inviter_name: str
    role_in_org: OrgRole
    target_email: str
    requires_password_setup: bool
    requires_microsoft_signin: bool
    is_existing_member: bool


class InvitationAcceptRequest(BaseModel):
    token: str
    full_name: str | None = None
    password: str | None = None
    ms_id_token: str | None = None


class InvitationResponse(BaseModel):
    id: str
    email: str
    organization_id: str
    role_in_org: OrgRole
    invited_by_user_id: str
    expires_at: datetime
    accepted_at: datetime | None = None
    revoked_at: datetime | None = None
    created_at: datetime | None = None
    is_expired: bool = False
    is_accepted: bool = False
    is_revoked: bool = False
