|
| 1 | +from mpt_api_client.models import ResourceData |
| 2 | + |
| 3 | +# TODO: Consider reorganizing functions in mixins to reduce duplication and differences amongst |
| 4 | +# different domains |
| 5 | + |
| 6 | + |
| 7 | +class ActivatableMixin[Model]: |
| 8 | + """Activatable mixin for activating, enabling, disabling and deactivating resources.""" |
| 9 | + |
| 10 | + def activate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 11 | + """Activate a resource. |
| 12 | +
|
| 13 | + Args: |
| 14 | + resource_id: Resource ID |
| 15 | + resource_data: Resource data will be updated |
| 16 | + """ |
| 17 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 18 | + resource_id, "POST", "activate", json=resource_data |
| 19 | + ) |
| 20 | + |
| 21 | + def deactivate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 22 | + """Deactivate a resource. |
| 23 | +
|
| 24 | + Args: |
| 25 | + resource_id: Resource ID |
| 26 | + resource_data: Resource data will be updated |
| 27 | + """ |
| 28 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 29 | + resource_id, "POST", "deactivate", json=resource_data |
| 30 | + ) |
| 31 | + |
| 32 | + def enable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 33 | + """Enable a resource. |
| 34 | +
|
| 35 | + Args: |
| 36 | + resource_id: Resource ID |
| 37 | + resource_data: Resource data will be updated |
| 38 | + """ |
| 39 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 40 | + resource_id, "POST", "enable", json=resource_data |
| 41 | + ) |
| 42 | + |
| 43 | + def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 44 | + """Disable a resource. |
| 45 | +
|
| 46 | + Args: |
| 47 | + resource_id: Resource ID |
| 48 | + resource_data: Resource data will be updated |
| 49 | + """ |
| 50 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 51 | + resource_id, "POST", "disable", json=resource_data |
| 52 | + ) |
| 53 | + |
| 54 | + |
| 55 | +class ValidateMixin[Model]: |
| 56 | + """Validate mixin adds the ability to validate a resource.""" |
| 57 | + |
| 58 | + def validate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 59 | + """Validate a resource. |
| 60 | +
|
| 61 | + Args: |
| 62 | + resource_id: Resource ID |
| 63 | + resource_data: Resource data will be validated |
| 64 | + """ |
| 65 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 66 | + resource_id, "POST", "validate", json=resource_data |
| 67 | + ) |
| 68 | + |
| 69 | + |
| 70 | +class AsyncActivatableMixin[Model]: |
| 71 | + """Async activatable mixin for activating, enabling, disabling and deactivating resources.""" |
| 72 | + |
| 73 | + async def activate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 74 | + """Activate a resource. |
| 75 | +
|
| 76 | + Args: |
| 77 | + resource_id: Resource ID |
| 78 | + resource_data: Resource data will be updated |
| 79 | + """ |
| 80 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 81 | + resource_id, "POST", "activate", json=resource_data |
| 82 | + ) |
| 83 | + |
| 84 | + async def deactivate( |
| 85 | + self, resource_id: str, resource_data: ResourceData | None = None |
| 86 | + ) -> Model: |
| 87 | + """Deactivate a resource. |
| 88 | +
|
| 89 | + Args: |
| 90 | + resource_id: Resource ID |
| 91 | + resource_data: Resource data will be updated |
| 92 | + """ |
| 93 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 94 | + resource_id, "POST", "deactivate", json=resource_data |
| 95 | + ) |
| 96 | + |
| 97 | + async def enable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 98 | + """Enable a resource. |
| 99 | +
|
| 100 | + Args: |
| 101 | + resource_id: Resource ID |
| 102 | + resource_data: Resource data will be updated |
| 103 | + """ |
| 104 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 105 | + resource_id, "POST", "enable", json=resource_data |
| 106 | + ) |
| 107 | + |
| 108 | + async def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 109 | + """Disable a resource. |
| 110 | +
|
| 111 | + Args: |
| 112 | + resource_id: Resource ID |
| 113 | + resource_data: Resource data will be updated |
| 114 | + """ |
| 115 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 116 | + resource_id, "POST", "disable", json=resource_data |
| 117 | + ) |
| 118 | + |
| 119 | + |
| 120 | +class AsyncValidateMixin[Model]: |
| 121 | + """Asynchronous Validate mixin adds the ability to validate a resource.""" |
| 122 | + |
| 123 | + async def validate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 124 | + """Validate a resource. |
| 125 | +
|
| 126 | + Args: |
| 127 | + resource_id: Resource ID |
| 128 | + resource_data: Resource data will be validated |
| 129 | + """ |
| 130 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 131 | + resource_id, "POST", "validate", json=resource_data |
| 132 | + ) |
0 commit comments