models.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from dataclasses import dataclass
  2. from datetime import datetime
  3. from typing import Any
  4. @dataclass(frozen=True, slots=True)
  5. class Plan:
  6. id: str
  7. code: str
  8. name: str
  9. summary: str = ""
  10. status: str = "ACTIVE"
  11. premium_cents: int = 0
  12. coverage_amount_cents: int = 0
  13. min_age: int = 0
  14. max_age: int = 100
  15. @dataclass(frozen=True, slots=True)
  16. class Product:
  17. id: str
  18. product_code: str
  19. name: str
  20. category: str
  21. summary: str
  22. status: str
  23. @dataclass(frozen=True, slots=True)
  24. class ProductVersion:
  25. id: str
  26. product_id: str
  27. version_no: str
  28. status: str
  29. effective_from: datetime
  30. effective_to: datetime | None
  31. plans: tuple[Plan, ...]
  32. rule_version: str = "eligibility-v1"
  33. rate_version: str = "rate-v1"
  34. terms_summary: str = ""
  35. def is_available_at(self, when: datetime) -> bool:
  36. return (
  37. self.status == "PUBLISHED"
  38. and self.effective_from <= when
  39. and (self.effective_to is None or when <= self.effective_to)
  40. )
  41. @dataclass(frozen=True, slots=True)
  42. class ProductChangeLog:
  43. id: str
  44. product_id: str
  45. version_id: str | None
  46. action: str
  47. actor_id: str
  48. actor_name: str
  49. detail: dict[str, Any]
  50. created_at: datetime