import { z } from 'zod';

import type { components } from './openapi/schema';
import { commonQuerySchema, stringArrayCoerce, stringCoerce } from './common';

export type Bookshelf = components['schemas']['ShelfRead'];

export const bookshelfQuerySchema = commonQuerySchema.extend({
	libraries: stringArrayCoerce,
	ids: stringArrayCoerce
});

export const modifyBooksInShelf = z.object({
	shelf_id: stringCoerce,
	book_ids: stringArrayCoerce
});

export const bookshelfCreate = z.object({
	title: z.string().min(1, 'Must have a title'),
	library_id: stringCoerce.optional(),
	book_ids: stringArrayCoerce.optional()
});

export type BookshelfQuerySchema = typeof bookshelfQuerySchema;
export type ModifyBooksInShelf = typeof modifyBooksInShelf;
