|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +This file is part of the Ingram Micro Cloud Blue Connect SDK. |
| 5 | +Copyright (c) 2019 Ingram Micro. All Rights Reserved. |
| 6 | +""" |
| 7 | +from marshmallow import fields, post_load |
| 8 | +from typing import Optional, List |
| 9 | + |
| 10 | +from connect.models import Param, ParamSchema |
| 11 | +from connect.models.base import BaseModel, BaseSchema |
| 12 | +from connect.models.company import Company, CompanySchema |
| 13 | +from connect.models.connection import Connection, ConnectionSchema |
| 14 | +from connect.models.contact import ContactInfo, ContactInfoSchema |
| 15 | +from connect.models.product import Product, ProductSchema |
| 16 | + |
| 17 | + |
| 18 | +class Account(BaseModel): |
| 19 | + name = None # type: str |
| 20 | + external_id = None # type: str |
| 21 | + external_uid = None # type: str |
| 22 | + contact_info = None # type: ContactInfo |
| 23 | + |
| 24 | + |
| 25 | +class EventInfo(BaseModel): |
| 26 | + at = None # type: str |
| 27 | + by = None # type: Company |
| 28 | + |
| 29 | + |
| 30 | +class Events(BaseModel): |
| 31 | + created = None # type: EventInfo |
| 32 | + inquired = None # type: EventInfo |
| 33 | + pended = None # type: EventInfo |
| 34 | + validated = None # type: EventInfo |
| 35 | + updated = None # type: EventInfo |
| 36 | + |
| 37 | + |
| 38 | +class Template(BaseModel): |
| 39 | + representation = None # type: str |
| 40 | + |
| 41 | + |
| 42 | +class TierConfig(BaseModel): |
| 43 | + name = None # type: str |
| 44 | + account = None # type: Account |
| 45 | + product = None # type: Product |
| 46 | + tier_level = None # type: int |
| 47 | + connection = None # type: Connection |
| 48 | + events = None # type: Events |
| 49 | + params = None # type: List[Param] |
| 50 | + template = None # type: Template |
| 51 | + |
| 52 | + # Undocumented fields (they appear in PHP SDK) |
| 53 | + open_request = None # type: BaseModel |
| 54 | + |
| 55 | + def get_param_by_id(self, id_): |
| 56 | + # type: (str) -> Optional[Param] |
| 57 | + try: |
| 58 | + return list(filter(lambda param: param.id == id_, self.params))[0] |
| 59 | + except IndexError: |
| 60 | + return None |
| 61 | + |
| 62 | + |
| 63 | +class Activation(BaseModel): |
| 64 | + link = None # type: str |
| 65 | + |
| 66 | + |
| 67 | +class TierConfigRequest(BaseModel): |
| 68 | + type = None # type: str |
| 69 | + status = None # type: str |
| 70 | + configuration = None # type: TierConfig |
| 71 | + events = None # type: Events |
| 72 | + params = None # type: List[Param] |
| 73 | + assignee = None # type: Company |
| 74 | + template = None # type: Template |
| 75 | + activation = None # type: Activation |
| 76 | + |
| 77 | + def get_param_by_id(self, id_): |
| 78 | + # type: (str) -> Optional[Param] |
| 79 | + try: |
| 80 | + return list(filter(lambda param: param.id == id_, self.params))[0] |
| 81 | + except IndexError: |
| 82 | + return None |
| 83 | + |
| 84 | + |
| 85 | +class AccountSchema(BaseSchema): |
| 86 | + name = fields.Str() |
| 87 | + external_id = fields.Str() |
| 88 | + external_uid = fields.Str() |
| 89 | + contact_info = fields.Nested(ContactInfoSchema) |
| 90 | + |
| 91 | + @post_load |
| 92 | + def make_object(self, data): |
| 93 | + return Account(**data) |
| 94 | + |
| 95 | + |
| 96 | +class EventInfoSchema(BaseSchema): |
| 97 | + at = fields.Str() |
| 98 | + by = fields.Nested(CompanySchema) |
| 99 | + |
| 100 | + @post_load |
| 101 | + def make_object(self, data): |
| 102 | + return EventInfo(**data) |
| 103 | + |
| 104 | + |
| 105 | +class EventsSchema(BaseSchema): |
| 106 | + created = fields.Nested(EventInfoSchema) |
| 107 | + inquired = fields.Nested(EventInfoSchema, required=False) |
| 108 | + pended = fields.Nested(EventInfoSchema, required=False) |
| 109 | + validated = fields.Nested(EventInfoSchema, required=False) |
| 110 | + updated = fields.Nested(EventInfoSchema, required=False) |
| 111 | + |
| 112 | + @post_load |
| 113 | + def make_object(self, data): |
| 114 | + return Events(**data) |
| 115 | + |
| 116 | + |
| 117 | +class TemplateSchema(BaseSchema): |
| 118 | + representation = fields.Str() |
| 119 | + |
| 120 | + @post_load |
| 121 | + def make_object(self, data): |
| 122 | + return Template(**data) |
| 123 | + |
| 124 | + |
| 125 | +class TierConfigSchema(BaseSchema): |
| 126 | + name = fields.Str() |
| 127 | + account = fields.Nested(AccountSchema) |
| 128 | + product = fields.Nested(ProductSchema) |
| 129 | + tier_level = fields.Int() |
| 130 | + connection = fields.Nested(ConnectionSchema) |
| 131 | + events = fields.Nested(EventsSchema) |
| 132 | + params = fields.List(fields.Nested(ParamSchema)) |
| 133 | + template = fields.Nested(TemplateSchema) |
| 134 | + |
| 135 | + # Undocumented fields (they appear in PHP SDK) |
| 136 | + open_request = fields.Nested(BaseSchema) |
| 137 | + |
| 138 | + @post_load |
| 139 | + def make_object(self, data): |
| 140 | + return TierConfig(**data) |
| 141 | + |
| 142 | + |
| 143 | +class ActivationSchema(BaseSchema): |
| 144 | + link = fields.Str() |
| 145 | + |
| 146 | + @post_load |
| 147 | + def make_object(self, data): |
| 148 | + return Activation(**data) |
| 149 | + |
| 150 | + |
| 151 | +class TierConfigRequestSchema(BaseSchema): |
| 152 | + type = fields.Str() |
| 153 | + status = fields.Str() |
| 154 | + configuration = fields.Nested(TierConfigSchema) |
| 155 | + events = fields.Nested(EventsSchema) |
| 156 | + params = fields.List(fields.Nested(ParamSchema)) |
| 157 | + assignee = fields.Nested(CompanySchema) |
| 158 | + template = fields.Nested(TemplateSchema) |
| 159 | + activation = fields.Nested(ActivationSchema) |
| 160 | + |
| 161 | + @post_load |
| 162 | + def make_object(self, data): |
| 163 | + return TierConfigRequest(**data) |
0 commit comments