Files
Hardik Sankhla 202e51c8a1 Initial commits
2025-06-27 05:56:40 +05:30

70 lines
3.6 KiB
Python

# D:\GNPL-Private\TimeCraft\backend\app\models\task.py
from datetime import time
from enum import Enum
from typing import List, Optional, Union
from pydantic import BaseModel, Field, conint, conlist
# Type aliases for Pydantic constrained types for better readability
PositiveInt = conint(gt=0)
WeekdayList = conlist(str, min_length=0, max_length=7)
# Enum for primary recurrence periods
class RecurrenceType(str, Enum):
daily = "daily"
weekly = "weekly"
monthly = "monthly"
# Enum for task categories
class TaskCategory(str, Enum):
personal = "personal"
work = "work"
errands = "errands"
extra = "extra"
# Enum for time units used in reminders or durations
class TimeUnit(str, Enum):
minutes = "Minutes"
hours = "Hours"
days = "Days"
# Pydantic model for time settings of a task
class TimeSettings(BaseModel):
start_time: Optional[time] = Field(None, description="Specific start time (HH:MM)")
end_time: Optional[time] = Field(None, description="Specific end time (HH:MM)")
duration: Optional[str] = Field(None, description="Duration of the task (e.g., '1 Hour', '30 Minutes'). Used if start_time and end_time are empty or to validate them.")
# Pydantic model for reminder settings
class ReminderOn(BaseModel):
is_active: bool = Field(False, description="Whether a reminder is set (true/false)")
numeric_input: Optional[PositiveInt] = Field(None, description="Numeric value for reminder (e.g., 10 minutes before)")
time_unit: Optional[TimeUnit] = Field(None, description="Unit for reminder time (Minutes, Hours, Days)")
# Main Pydantic model for the task creation request from the frontend
class TaskCreateRequest(BaseModel):
type: RecurrenceType = Field(..., description="Defines the primary recurrence period (daily, weekly, monthly)")
task_name: str = Field(..., min_length=1, description="A descriptive name for the task")
task_description: Optional[str] = Field(None, description="Detailed notes or description of the task")
time_settings: TimeSettings = Field(..., description="Time settings for the task, including start, end, and duration")
category: TaskCategory = Field(..., description="Categorizes the task (personal, work, errands, extra)")
repeat_on_1: Optional[str] = Field(None, description="CRITICAL for complex recurrence patterns. Free-form text field for custom recurrence rules (e.g., 'Every second Monday')")
repeat_on_2: Optional[WeekdayList] = Field(
None,
description="Checkbox selector for days of the week (S, M, T, W, T, F, S). Users can select multiple days."
)
reminder_on: ReminderOn = Field(..., description="Reminder settings for the task")
# Pydantic model for a single scheduled task returned by the LLM
class ScheduledTask(BaseModel):
task_name: str = Field(..., description="Name of the scheduled task")
date: str = Field(..., description="Scheduled date in ISO-MM-DD format")
start_time: Optional[str] = Field(None, description="Scheduled start time in HH:MM format")
end_time: Optional[str] = Field(None, description="Scheduled end time in HH:MM format")
category: TaskCategory = Field(..., description="Category of the scheduled task")
original_task_id: Optional[str] = Field(None, description="Optional ID to link back to the original task request, useful for updates/tracking")
# reminder_on: Optional[ReminderOn] = Field(None, description="Reminder settings for the scheduled task") # Uncomment if LLM output includes this
# Pydantic model for the overall schedule response from the LLM
class ScheduleResponse(BaseModel):
scheduled_tasks: List[ScheduledTask] = Field(..., description="List of intelligently assigned scheduled tasks")