import "reflect-metadata";
import { Controller, Get, Post, Put, Delete, Route, Path, Body } from "@tsoa/runtime";
import { getList, getOne, add, update, remove } from "~/services/wishlist";

@Route("wishlist")
export class WishlistController extends Controller {
	/**
	 * Retrieves public wishlist
	 */
	@Get("/public")
	public async getPublic(): Promise<any> {
		return await getList(1);
	}

	/**
	 * Retrieves authenticated wishlist
	 */
	@Get("/authenticated")
	public async getAuthenticated(): Promise<any> {
		return await getList(0);
	}

	/**
	 * Retrieves a specific wishlist item
	 */
	@Get("/:path/:wishlistID")
	public async getOneItem(@Path() path: string, @Path() wishlistID: string | number): Promise<any> {
		return await getOne(path, wishlistID);
	}

	/**
	 * Creates a new wishlist item
	 */
	@Post()
	public async addItem(@Body() body: any): Promise<any> {
		try {
			return await add(body);
		} catch (err) {
			this.setStatus(500);
			return (err as any).message;
		}
	}

	/**
	 * Updates a wishlist item
	 */
	@Put("/:id")
	public async updateItem(@Path() id: string | number, @Body() body: any): Promise<any> {
		return await update(id, body);
	}

	/**
	 * Deletes a wishlist item
	 */
	@Delete("/:id")
	public async deleteItem(@Path() id: string | number): Promise<any> {
		return await remove(id);
	}
}
