from datetime import date
from typing import Annotated

from fastapi import Depends, Query
from fastapi.exceptions import HTTPException
from pydantic import BaseModel, model_validator

from src.schemas.tasks import PriorityEnum, StatusEnum


class Date(BaseModel):
    date_from: date | None = Query(default=None)
    date_to: date | None = Query(default=None)

    @model_validator(mode="after")
    def check_dates(self):
        if self.date_from and self.date_to and self.date_to < self.date_from:
            raise HTTPException(
                status_code=422, detail="date_to cannot be less than date_from"
            )
        return self


class Page(BaseModel):
    limit: int = Query(default=30, ge=1, le=100)
    page: int | None = Query(default=1, ge=1)


class Status(BaseModel):
    status: StatusEnum | None = Query(default=None)


class Priority(BaseModel):
    priority: PriorityEnum | None = Query(default=None)


class Filters(Date, Status, Priority, Page):
    pass


FilterDep = Annotated[Filters, Depends()]
