from pydantic import BaseModel, validator
from datetime import datetime, timezone


# ------------------------------------------------------------------------------
class Attendee(BaseModel, extra="forbid"):
    email: str
    name: str


# ------------------------------------------------------------------------------
class Appointment(BaseModel, extra="forbid"):
    start_time: datetime
    end_time: datetime

    # To compare two Appointment objects
    def __hash__(self):
        return hash((self.start_time, self.end_time))


# ------------------------------------------------------------------------------
class CreateParams(BaseModel, extra="forbid"):
    appointment: Appointment
    subject: str
    recruiter: Attendee
    client: Attendee
    candidate: Attendee


# ------------------------------------------------------------------------------
class SendClientParams(BaseModel, extra="forbid"):
    client_email: str
    candidate_name: str
    job_title: str


# ------------------------------------------------------------------------------
class AppointmentDBItem(BaseModel, extra="forbid"):
    id: str
    zoom_meeting_id: str
    process_id: str
    job_title: str
    start_time: str
    end_time: str
    meeting_url: str
    environment: str
    process_status: str
    recruiter: Attendee
    client: Attendee
    candidate: Attendee
    summary_recruiter: str
    summary_client: str
    summary_candidate: str
    
    
# ------------------------------------------------------------------------------
class SendCandidateParams(BaseModel, extra="forbid"):
    appointment_suggestions: list[Appointment]
    candidate_email: str
    job_title: str

    @validator("appointment_suggestions")
    def check_length(cls, appointment_list):
        if len(appointment_list) < 3:
            raise ValueError(
                "appointment_suggestions must contain at least 3 items"
            )

        if len(appointment_list) != len(set(appointment_list)):
            raise ValueError("All suggestions must be unique.")

        current_datetime = datetime.now(timezone.utc)
        if not all(
            appointment.start_time > current_datetime
            and appointment.end_time > current_datetime
            for appointment in appointment_list
        ):
            raise ValueError(
                "All suggestions must refer to appointments in the future."
            )

        return list