<?php
declare(strict_types=1);
namespace FreshCloud\Mail\PocketBaseAdapter;
final class RealPocketBaseAdapter implements PocketBaseAdapter {
    public function __construct(private \Pocketbase\Sdk\PocketBase $pb) {}
    public function collection(string $name): CollectionAdapter {
        return new RealCollectionAdapter($this->pb, $name);
    }
}
final class RealCollectionAdapter implements CollectionAdapter {
    public function __construct(private \Pocketbase\Sdk\PocketBase $pb, private string $name) {}
    public function create(array $data): array { return (array) $this->pb->collection($this->name)->create($data); }
    public function getOne(string $id): array { return (array) $this->pb->collection($this->name)->getOne($id); }
    public function getList(int $page, int $perPage, array $opts = []): array {
        $r = $this->pb->collection($this->name)->getList($page, $perPage, $opts);
        if (is_array($r) && isset($r['items'])) return ['items' => array_map(fn($i) => (array) $i, $r['items'])];
        return ['items' => []];
    }
    public function update(string $id, array $data): array { return (array) $this->pb->collection($this->name)->update($id, $data); }
    public function delete(string $id): void { $this->pb->collection($this->name)->delete($id); }
}
