import type { StorageRepository } from "./repositories/storage.ts";

export function createStorageApi(repository: Pick<StorageRepository, "usage">) {
  return {
    async get(): Promise<Response> {
      try {
        return Response.json({ storage: await repository.usage() });
      } catch (cause) {
        return Response.json({
          error: { code: "storage_unavailable", message: cause instanceof Error ? cause.message : "存储状态无法加载。" },
        }, { status: 500 });
      }
    },
  };
}
