Coverage for src / ai_lls_lib / core / models.py: 100%

43 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-06 23:45 +0000

1""" 

2Data models for phone verification 

3""" 

4 

5from datetime import datetime 

6from enum import StrEnum 

7 

8from pydantic import BaseModel, Field 

9 

10 

11class LineType(StrEnum): 

12 """Phone line type enumeration""" 

13 

14 MOBILE = "mobile" 

15 LANDLINE = "landline" 

16 VOIP = "voip" 

17 UNKNOWN = "unknown" 

18 

19 

20class VerificationSource(StrEnum): 

21 """Source of verification data""" 

22 

23 API = "api" 

24 CACHE = "cache" 

25 BULK_IMPORT = "bulk_import" 

26 

27 

28class JobStatus(StrEnum): 

29 """Bulk job status enumeration""" 

30 

31 PENDING = "pending" 

32 PROCESSING = "processing" 

33 COMPLETED = "completed" 

34 FAILED = "failed" 

35 

36 

37class PhoneVerification(BaseModel): 

38 """Result of phone number verification""" 

39 

40 phone_number: str = Field(..., description="E.164 formatted phone number") 

41 line_type: LineType = Field(..., description="Type of phone line") 

42 dnc: bool = Field(..., description="Whether number is on DNC list") 

43 cached: bool = Field(..., description="Whether result came from cache") 

44 verified_at: datetime = Field(..., description="When verification occurred") 

45 source: VerificationSource = Field(..., description="Source of verification data") 

46 

47 class Config: 

48 json_encoders = {datetime: lambda v: v.isoformat()} 

49 

50 

51class BulkJob(BaseModel): 

52 """Bulk processing job metadata""" 

53 

54 job_id: str = Field(..., description="Unique job identifier") 

55 status: JobStatus = Field(..., description="Current job status") 

56 

57 

58class BulkJobStatus(BulkJob): 

59 """Extended bulk job status with progress info""" 

60 

61 total_rows: int | None = Field(None, description="Total rows to process") 

62 processed_rows: int | None = Field(None, description="Rows processed so far") 

63 result_url: str | None = Field(None, description="S3 URL of results") 

64 created_at: datetime = Field(..., description="Job creation time") 

65 completed_at: datetime | None = Field(None, description="Job completion time") 

66 error: str | None = Field(None, description="Error message if failed") 

67 

68 

69class CacheEntry(BaseModel): 

70 """DynamoDB cache entry""" 

71 

72 phone_number: str 

73 line_type: str # Stored as string in DynamoDB 

74 dnc: bool 

75 verified_at: str # ISO format string 

76 source: str # Stored as string in DynamoDB 

77 ttl: int # Unix timestamp for DynamoDB TTL