File size: 1,840 Bytes
54af9e3
cb7ff7d
54af9e3
 
cb7ff7d
 
 
 
 
 
 
 
54af9e3
 
 
 
cb7ff7d
 
 
54af9e3
 
cb7ff7d
54af9e3
 
 
 
 
cb7ff7d
 
54af9e3
 
cb7ff7d
54af9e3
cb7ff7d
54af9e3
 
 
 
 
 
 
cb7ff7d
54af9e3
cb7ff7d
54af9e3
 
 
 
 
 
 
 
cb7ff7d
54af9e3
cb7ff7d
54af9e3
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import abc
from enum import Enum


class DetailsType(Enum):
    PERSONAL_DETAILS = 1
    LOCATION_DETAILS = 2
    CONTRACTOR_DETAILS = 3

    @classmethod
    def values(cls):
        return [cls.PERSONAL_DETAILS, cls.LOCATION_DETAILS, cls.CONTRACTOR_DETAILS]


class SavedDetails(abc.ABC):

    excluded_fields = ["type_"]
    def __init__(self, type_: DetailsType):
        self.type_ = type_

    @classmethod
    def load(cls, data: dict):
        type_ = data.get("type_")
        if not type_ or type_ != cls.type_:
            raise ValueError(f"the expected type is {cls.type_} but is actually {type_}")
        return cls.__init__(**{k: v for k, v in data if k != "type"})

    def to_json(self):
        return {k:v for k,v in self.__dict__.items() if k not in self.excluded_fields}

class PersonalDetails(SavedDetails):
    type_ = DetailsType.PERSONAL_DETAILS

    def __init__(self, full_name, email, contact_number, *_):
        super().__init__(self.type_)
        self.full_name = full_name
        self.email = email
        self.contact_number = contact_number


class LocationDetails(SavedDetails):
    type_ = DetailsType.LOCATION_DETAILS

    def __init__(self, owner_or_tenant: str, community: str, building: str, unit_number: str, *_):
        super().__init__(self.type_)
        self.owner_or_tenant = owner_or_tenant
        self.community = community
        self.building = building
        self.unit_number = unit_number


class ContractorDetails(SavedDetails):
    type_ = DetailsType.CONTRACTOR_DETAILS

    def __init__(self, contractor_name: str, contractor_contact_number: str, contractor_email: str, *_):
        super().__init__(self.type_)
        self.contractor_name = contractor_name
        self.contractor_contact_number = contractor_contact_number
        self.contractor_email = contractor_email