You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.2 KiB

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023, Joas Schilling <coding@schilljs.com>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OCA\Talk\Model;
  23. use OCA\Talk\ResponseDefinitions;
  24. use OCP\AppFramework\Db\Entity;
  25. /**
  26. * @method void setName(string $name)
  27. * @method string getName()
  28. * @method void setUrl(string $url)
  29. * @method string getUrl()
  30. * @method void setUrlHash(string $urlHash)
  31. * @method string getUrlHash()
  32. * @method void setDescription(?string $description)
  33. * @method null|string getDescription()
  34. * @method void setSecret(string $secret)
  35. * @method string getSecret()
  36. * @method void setErrorCount(int $errorCount)
  37. * @method int getErrorCount()
  38. * @method void setLastErrorDate(?\DateTimeImmutable $lastErrorDate)
  39. * @method ?\DateTimeImmutable getLastErrorDate()
  40. * @method void setLastErrorMessage(string $lastErrorMessage)
  41. * @method string getLastErrorMessage()
  42. * @method void setState(int $state)
  43. * @method int getState()
  44. * @method void setFeatures(int $features)
  45. * @method int getFeatures()
  46. *
  47. * @psalm-import-type TalkBotWithDetailsAndSecret from ResponseDefinitions
  48. */
  49. class BotServer extends Entity implements \JsonSerializable {
  50. protected string $name = '';
  51. protected string $url = '';
  52. protected string $urlHash = '';
  53. protected ?string $description = null;
  54. protected string $secret = '';
  55. protected int $errorCount = 0;
  56. protected ?\DateTimeImmutable $lastErrorDate = null;
  57. protected ?string $lastErrorMessage = null;
  58. protected int $state = Bot::STATE_DISABLED;
  59. protected int $features = Bot::FEATURE_NONE;
  60. public function __construct() {
  61. $this->addType('name', 'string');
  62. $this->addType('url', 'string');
  63. $this->addType('url_hash', 'string');
  64. $this->addType('description', 'string');
  65. $this->addType('secret', 'string');
  66. $this->addType('error_count', 'int');
  67. $this->addType('last_error_date', 'datetime');
  68. $this->addType('last_error_message', 'string');
  69. $this->addType('state', 'int');
  70. $this->addType('features', 'int');
  71. }
  72. /**
  73. * @return TalkBotWithDetailsAndSecret
  74. */
  75. public function jsonSerialize(): array {
  76. return [
  77. 'id' => $this->getId(),
  78. 'name' => $this->getName(),
  79. 'url' => $this->getUrl(),
  80. 'url_hash' => $this->getUrlHash(),
  81. 'description' => $this->getDescription(),
  82. 'secret' => $this->getSecret(),
  83. 'error_count' => $this->getErrorCount(),
  84. 'last_error_date' => $this->getLastErrorDate() ? $this->getLastErrorDate()->getTimestamp() : 0,
  85. 'last_error_message' => $this->getLastErrorMessage(),
  86. 'state' => $this->getState(),
  87. 'features' => $this->getFeatures(),
  88. ];
  89. }
  90. }