import { request } from './client';

export type Tag = {
    id: string;
    name: string;
    created_at: string;
};

export type ListTagsOptions = {
    search?: string;
    limit?: number;
};

/** Autocomplete for the tag input. Server sorts by trigram similarity. */
export async function listTags(opts: ListTagsOptions = {}): Promise<Tag[]> {
    const params = new URLSearchParams();
    if (opts.search) params.set('search', opts.search);
    if (opts.limit != null) params.set('limit', String(opts.limit));
    const qs = params.toString();
    return request<Tag[]>(`/v1/tags${qs ? `?${qs}` : ''}`);
}
