acceptJson()->timeout(10); } /** All email domains for the user. */ public function forUser(string $publicId): array { return $this->data($this->http()->get($this->base(), ['user' => $publicId])); } /** Only verified/active domains (eligible for mailboxes). */ public function verified(string $publicId): array { return $this->data($this->http()->get($this->base(), ['user' => $publicId, 'status' => 'active'])); } public function find(string $publicId, int $id): ?array { return collect($this->forUser($publicId))->firstWhere('id', $id) ?: null; } /** Full detail (incl. DNS records to publish) for one domain. */ public function show(string $publicId, int $id): array { return $this->data($this->http()->get($this->base().'/'.$id, ['user' => $publicId])); } /** Add an email domain. Returns its detail. */ public function create(string $publicId, string $domain, string $method = 'dns_record'): array { $res = $this->http()->post($this->base(), ['user' => $publicId, 'domain' => $domain, 'verification_method' => $method]); $res->throw(); return (array) $res->json('data'); } /** Run verification; returns updated detail. */ public function verify(string $publicId, int $id): array { $res = $this->http()->post($this->base().'/'.$id.'/verify', ['user' => $publicId]); $res->throw(); return (array) $res->json('data'); } public function delete(string $publicId, int $id): void { $this->http()->delete($this->base().'/'.$id, ['user' => $publicId])->throw(); } private function data($res): array { $res->throw(); return (array) ($res->json('data') ?? $res->json()); } }