File size: 1,695 Bytes
de1e3fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import annotations

from datetime import date

from sqlalchemy import Date, Enum as SAEnum, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from .base import Base, CaseStatus, CaseType, TimestampMixin


class Case(Base, TimestampMixin):
    """A lost or found case (spec §7.4)."""

    __tablename__ = "cases"

    id: Mapped[int] = mapped_column(primary_key=True)
    # null for anonymous finder
    person_id: Mapped[int | None] = mapped_column(
        ForeignKey("users.id"), nullable=True, index=True
    )
    # anonymous finder contact (spec §7.4)
    finder_name: Mapped[str | None] = mapped_column(String(120), nullable=True)
    finder_email: Mapped[str | None] = mapped_column(String(255), nullable=True)
    finder_phone: Mapped[str | None] = mapped_column(String(40), nullable=True)

    known_dog_id: Mapped[int | None] = mapped_column(
        ForeignKey("known_dogs.id"), nullable=True
    )
    unknown_dog_id: Mapped[int | None] = mapped_column(
        ForeignKey("unknown_dogs.id"), nullable=True
    )

    type: Mapped[CaseType] = mapped_column(SAEnum(CaseType, native_enum=False))
    event_zip: Mapped[str] = mapped_column(String(10), index=True)
    event_date: Mapped[date] = mapped_column(Date)
    current_location: Mapped[str | None] = mapped_column(String(255), nullable=True)
    # current widening level (miles); defaults to first radius level
    search_radius_miles: Mapped[int] = mapped_column(Integer, default=0)
    notes: Mapped[str | None] = mapped_column(Text, nullable=True)
    status: Mapped[CaseStatus] = mapped_column(
        SAEnum(CaseStatus, native_enum=False), default=CaseStatus.open
    )