id = isset($data['id']) ? (int)$data['id'] : null; $this->connectionId = $data['connection_id'] ?? ''; $this->spreadsheetId = $data['spreadsheet_id'] ?? ''; $this->worksheetName = $data['worksheet_name'] ?? 'Sheet1'; $payloadVal = $data['payload'] ?? []; $this->payload = is_string($payloadVal) ? (json_decode($payloadVal, true) ?: []) : $payloadVal; $this->attempts = (int)($data['attempts'] ?? 0); $this->status = $data['status'] ?? 'pending'; $this->errorMessage = $data['error_message'] ?? null; $this->nextAttemptAt = $data['next_attempt_at'] ?? null; $this->createdAt = $data['created_at'] ?? current_time('mysql'); $this->updatedAt = $data['updated_at'] ?? current_time('mysql'); } /** * Convert the entity to an array format suitable for database insert/updates. * * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'connection_id' => $this->connectionId, 'spreadsheet_id' => $this->spreadsheetId, 'worksheet_name' => $this->worksheetName, 'payload' => json_encode($this->payload), 'attempts' => $this->attempts, 'status' => $this->status, 'error_message' => $this->errorMessage, 'next_attempt_at' => $this->nextAttemptAt, 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt, ]; } // Getters and Setters public function getId(): ?int { return $this->id; } public function setId(int $id): void { $this->id = $id; } public function getConnectionId(): string { return $this->connectionId; } public function setConnectionId(string $connectionId): void { $this->connectionId = $connectionId; } public function getSpreadsheetId(): string { return $this->spreadsheetId; } public function setSpreadsheetId(string $spreadsheetId): void { $this->spreadsheetId = $spreadsheetId; } public function getWorksheetName(): string { return $this->worksheetName; } public function setWorksheetName(string $worksheetName): void { $this->worksheetName = $worksheetName; } public function getPayload(): array { return $this->payload; } public function setPayload(array $payload): void { $this->payload = $payload; } public function getAttempts(): int { return $this->attempts; } public function setAttempts(int $attempts): void { $this->attempts = $attempts; } public function getStatus(): string { return $this->status; } public function setStatus(string $status): void { $this->status = $status; } public function getErrorMessage(): ?string { return $this->errorMessage; } public function setErrorMessage(?string $errorMessage): void { $this->errorMessage = $errorMessage; } public function getNextAttemptAt(): ?string { return $this->nextAttemptAt; } public function setNextAttemptAt(?string $nextAttemptAt): void { $this->nextAttemptAt = $nextAttemptAt; } 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; } }