|
| 1 | +from mpt_api_client.models import ResourceData |
| 2 | + |
| 3 | + |
| 4 | +class IssuableMixin[Model]: |
| 5 | + """Issuable mixin adds the ability to issue resources.""" |
| 6 | + |
| 7 | + def issue(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 8 | + """Issue resource. |
| 9 | +
|
| 10 | + Args: |
| 11 | + resource_id: Resource ID |
| 12 | + resource_data: Resource data will be updated |
| 13 | + """ |
| 14 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 15 | + resource_id, "POST", "issue", json=resource_data |
| 16 | + ) |
| 17 | + |
| 18 | + def cancel(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 19 | + """Cancel resource. |
| 20 | +
|
| 21 | + Args: |
| 22 | + resource_id: Resource ID |
| 23 | + resource_data: Resource data will be updated |
| 24 | + """ |
| 25 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 26 | + resource_id, "POST", "cancel", json=resource_data |
| 27 | + ) |
| 28 | + |
| 29 | + def error(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 30 | + """Error resource. |
| 31 | +
|
| 32 | + Args: |
| 33 | + resource_id: Resource ID |
| 34 | + resource_data: Resource data will be updated |
| 35 | + """ |
| 36 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 37 | + resource_id, "POST", "error", json=resource_data |
| 38 | + ) |
| 39 | + |
| 40 | + def pending(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 41 | + """Pending resource. |
| 42 | +
|
| 43 | + Args: |
| 44 | + resource_id: Resource ID |
| 45 | + resource_data: Resource data will be updated |
| 46 | + """ |
| 47 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 48 | + resource_id, "POST", "pending", json=resource_data |
| 49 | + ) |
| 50 | + |
| 51 | + def queue(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 52 | + """Queue resource. |
| 53 | +
|
| 54 | + Args: |
| 55 | + resource_id: Resource ID |
| 56 | + resource_data: Resource data will be updated |
| 57 | + """ |
| 58 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 59 | + resource_id, "POST", "queue", json=resource_data |
| 60 | + ) |
| 61 | + |
| 62 | + def retry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 63 | + """Retry resource. |
| 64 | +
|
| 65 | + Args: |
| 66 | + resource_id: Resource ID |
| 67 | + resource_data: Resource data will be updated |
| 68 | + """ |
| 69 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 70 | + resource_id, "POST", "retry", json=resource_data |
| 71 | + ) |
| 72 | + |
| 73 | + def recalculate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 74 | + """Recalculate resource. |
| 75 | +
|
| 76 | + Args: |
| 77 | + resource_id: Resource ID |
| 78 | + resource_data: Resource data will be updated |
| 79 | + """ |
| 80 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 81 | + resource_id, "POST", "recalculate", json=resource_data |
| 82 | + ) |
| 83 | + |
| 84 | + |
| 85 | +class AsyncIssuableMixin[Model]: |
| 86 | + """Issuable mixin adds the ability to issue resources.""" |
| 87 | + |
| 88 | + async def issue(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 89 | + """Issue resource. |
| 90 | +
|
| 91 | + Args: |
| 92 | + resource_id: Resource ID |
| 93 | + resource_data: Resource data will be updated |
| 94 | + """ |
| 95 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 96 | + resource_id, "POST", "issue", json=resource_data |
| 97 | + ) |
| 98 | + |
| 99 | + async def cancel(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 100 | + """Cancel resource. |
| 101 | +
|
| 102 | + Args: |
| 103 | + resource_id: Resource ID |
| 104 | + resource_data: Resource data will be updated |
| 105 | + """ |
| 106 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 107 | + resource_id, "POST", "cancel", json=resource_data |
| 108 | + ) |
| 109 | + |
| 110 | + async def error(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 111 | + """Error resource. |
| 112 | +
|
| 113 | + Args: |
| 114 | + resource_id: Resource ID |
| 115 | + resource_data: Resource data will be updated |
| 116 | + """ |
| 117 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 118 | + resource_id, "POST", "error", json=resource_data |
| 119 | + ) |
| 120 | + |
| 121 | + async def pending(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 122 | + """Pending resource. |
| 123 | +
|
| 124 | + Args: |
| 125 | + resource_id: Resource ID |
| 126 | + resource_data: Resource data will be updated |
| 127 | + """ |
| 128 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 129 | + resource_id, "POST", "pending", json=resource_data |
| 130 | + ) |
| 131 | + |
| 132 | + async def queue(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 133 | + """Queue resource. |
| 134 | +
|
| 135 | + Args: |
| 136 | + resource_id: Resource ID |
| 137 | + resource_data: Resource data will be updated |
| 138 | + """ |
| 139 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 140 | + resource_id, "POST", "queue", json=resource_data |
| 141 | + ) |
| 142 | + |
| 143 | + async def retry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 144 | + """Retry resource. |
| 145 | +
|
| 146 | + Args: |
| 147 | + resource_id: Resource ID |
| 148 | + resource_data: Resource data will be updated |
| 149 | + """ |
| 150 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 151 | + resource_id, "POST", "retry", json=resource_data |
| 152 | + ) |
| 153 | + |
| 154 | + async def recalculate( |
| 155 | + self, resource_id: str, resource_data: ResourceData | None = None |
| 156 | + ) -> Model: |
| 157 | + """Recalculate resource. |
| 158 | +
|
| 159 | + Args: |
| 160 | + resource_id: Resource ID |
| 161 | + resource_data: Resource data will be updated |
| 162 | + """ |
| 163 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 164 | + resource_id, "POST", "recalculate", json=resource_data |
| 165 | + ) |
0 commit comments