id = $data['id'] ?? ''; $this->name = $data['name'] ?? ''; $this->email = $data['email'] ?? ''; $this->clientId = $data['client_id'] ?? ''; $this->clientSecret = $data['client_secret'] ?? ''; $this->refreshToken = $data['refresh_token'] ?? ''; $this->accessToken = $data['access_token'] ?? ''; $this->scopes = is_string($data['scopes'] ?? null) ? explode(',', $data['scopes']) : (is_array($data['scopes'] ?? null) ? $data['scopes'] : []); $this->ownerId = (int)($data['owner_id'] ?? get_current_user_id()); $this->status = $data['status'] ?? 'active'; $this->createdAt = $data['created_at'] ?? current_time('mysql'); $this->updatedAt = $data['updated_at'] ?? current_time('mysql'); $this->lastSuccessAt = $data['last_success_at'] ?? null; $this->lastError = $data['last_error'] ?? null; } public function toArray(): array { return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, 'client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'refresh_token' => $this->refreshToken, 'access_token' => $this->accessToken, 'scopes' => implode(',', $this->scopes), 'owner_id' => $this->ownerId, 'status' => $this->status, 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt, 'last_success_at' => $this->lastSuccessAt, 'last_error' => $this->lastError, ]; } // Getters and Setters public function getId(): string { return $this->id; } public function setId(string $id): void { $this->id = $id; } public function getName(): string { return $this->name; } public function setName(string $name): void { $this->name = $name; } public function getEmail(): string { return $this->email; } public function setEmail(string $email): void { $this->email = $email; } public function getClientId(): string { return $this->clientId; } public function setClientId(string $clientId): void { $this->clientId = $clientId; } public function getClientSecret(): string { return $this->clientSecret; } public function setClientSecret(string $clientSecret): void { $this->clientSecret = $clientSecret; } public function getRefreshToken(): string { return $this->refreshToken; } public function setRefreshToken(string $refreshToken): void { $this->refreshToken = $refreshToken; } public function getAccessToken(): string { return $this->accessToken; } public function setAccessToken(string $accessToken): void { $this->accessToken = $accessToken; } public function getScopes(): array { return $this->scopes; } public function setScopes(array $scopes): void { $this->scopes = $scopes; } public function getOwnerId(): int { return $this->ownerId; } public function setOwnerId(int $ownerId): void { $this->ownerId = $ownerId; } public function getStatus(): string { return $this->status; } public function setStatus(string $status): void { $this->status = $status; } public function getCreatedAt(): string { return $this->createdAt; } public function setCreatedAt(string $createdAt): void { $this->createdAt = $createdAt; } public function getUpdatedAt(): string { return $this->updatedAt; } public function setUpdatedAt(string $updatedAt): void { $this->updatedAt = $updatedAt; } public function getLastSuccessAt(): ?string { return $this->lastSuccessAt; } public function setLastSuccessAt(?string $lastSuccessAt): void { $this->lastSuccessAt = $lastSuccessAt; } public function getLastError(): ?string { return $this->lastError; } public function setLastError(?string $lastError): void { $this->lastError = $lastError; } }