|
| 1 | +import datetime as dt |
| 2 | +from typing import ClassVar, Optional, cast |
| 3 | + |
| 4 | +from cuenca_validations.types import Country, PlatformRequest, State |
| 5 | + |
| 6 | +from ..http import Session, session as global_session |
| 7 | +from .base import Creatable |
| 8 | + |
| 9 | + |
| 10 | +class Platform(Creatable): |
| 11 | + _resource: ClassVar = 'platforms' |
| 12 | + |
| 13 | + created_at: dt.datetime |
| 14 | + name: str |
| 15 | + rfc_curp: Optional[str] = None |
| 16 | + establishment_date: Optional[dt.date] = None |
| 17 | + country: Optional[Country] = None |
| 18 | + state: Optional[State] = None |
| 19 | + economic_activity: Optional[str] = None |
| 20 | + email_address: Optional[str] = None |
| 21 | + phone_number: Optional[str] = None |
| 22 | + |
| 23 | + class Config: |
| 24 | + fields = { |
| 25 | + 'name': {'description': 'name of the platform being created'}, |
| 26 | + 'rfc_curp': {'description': 'RFC or CURP of the platform'}, |
| 27 | + 'establishment_date': { |
| 28 | + 'description': 'when the platform was established' |
| 29 | + }, |
| 30 | + 'country': {'description': 'country where the platform resides'}, |
| 31 | + 'state': {'description': 'state where the platform resides'}, |
| 32 | + 'economic_activity': {'description': 'what the platform does'}, |
| 33 | + 'phone_number': { |
| 34 | + 'description': 'phone number to contact the platform' |
| 35 | + }, |
| 36 | + 'email_address': { |
| 37 | + 'description': 'email address to contact the platform' |
| 38 | + }, |
| 39 | + } |
| 40 | + schema_extra = { |
| 41 | + 'example': { |
| 42 | + 'id': 'PT0123456789', |
| 43 | + 'name': 'Arteria', |
| 44 | + 'created_at': '2021-08-24T14:15:22Z', |
| 45 | + 'rfc_curp': 'ART123456FFF', |
| 46 | + 'establishment_date': '2021-08-24T14:15:22Z', |
| 47 | + 'country': 'MX', |
| 48 | + 'state': 'DF', |
| 49 | + 'economic_activity': 'fiinances and technologies', |
| 50 | + 'phone_number': '+525555555555', |
| 51 | + 'email_address': 'art@eria.com', |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @classmethod |
| 56 | + def create( |
| 57 | + cls, |
| 58 | + name: str, |
| 59 | + rfc_curp: Optional[str] = None, |
| 60 | + establishment_date: Optional[str] = None, |
| 61 | + country: Optional[Country] = None, |
| 62 | + state: Optional[State] = None, |
| 63 | + economic_activity: Optional[str] = None, |
| 64 | + phone_number: Optional[str] = None, |
| 65 | + email_address: Optional[str] = None, |
| 66 | + *, |
| 67 | + session: Session = global_session, |
| 68 | + ) -> 'Platform': |
| 69 | + req = PlatformRequest( |
| 70 | + name=name, |
| 71 | + rfc_curp=rfc_curp, |
| 72 | + establishment_date=establishment_date, |
| 73 | + country=country, |
| 74 | + state=state, |
| 75 | + economic_activity=economic_activity, |
| 76 | + phone_number=phone_number, |
| 77 | + email_address=email_address, |
| 78 | + ) |
| 79 | + return cast('Platform', cls._create(session=session, **req.dict())) |
0 commit comments