/* tslint:disable */
/* eslint-disable */
/**
 * Jellyfin API
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 10.8.9
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


import * as runtime from '../runtime';
import type {
  BaseItemDtoQueryResult,
  CreatePlaylistRequest,
  ImageType,
  ItemFields,
  PlaylistCreationResult,
} from '../models';
import {
    BaseItemDtoQueryResultFromJSON,
    BaseItemDtoQueryResultToJSON,
    CreatePlaylistRequestFromJSON,
    CreatePlaylistRequestToJSON,
    ImageTypeFromJSON,
    ImageTypeToJSON,
    ItemFieldsFromJSON,
    ItemFieldsToJSON,
    PlaylistCreationResultFromJSON,
    PlaylistCreationResultToJSON,
} from '../models';

export interface AddToPlaylistRequest {
    playlistId: string;
    ids?: Array<string>;
    userId?: string;
}

export interface CreatePlaylistOperationRequest {
    name?: string;
    ids?: Array<string>;
    userId?: string;
    mediaType?: string;
    createPlaylistRequest?: CreatePlaylistRequest;
}

export interface GetPlaylistItemsRequest {
    playlistId: string;
    userId: string;
    startIndex?: number;
    limit?: number;
    fields?: Array<ItemFields>;
    enableImages?: boolean;
    enableUserData?: boolean;
    imageTypeLimit?: number;
    enableImageTypes?: Array<ImageType>;
}

export interface MoveItemRequest {
    playlistId: string;
    itemId: string;
    newIndex: number;
}

export interface RemoveFromPlaylistRequest {
    playlistId: string;
    entryIds?: Array<string>;
}

/**
 * 
 */
export class PlaylistsApi extends runtime.BaseAPI {

    /**
     * Adds items to a playlist.
     */
    async addToPlaylistRaw(requestParameters: AddToPlaylistRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.playlistId === null || requestParameters.playlistId === undefined) {
            throw new runtime.RequiredError('playlistId','Required parameter requestParameters.playlistId was null or undefined when calling addToPlaylist.');
        }

        const queryParameters: any = {};

        if (requestParameters.ids) {
            queryParameters['ids'] = requestParameters.ids;
        }

        if (requestParameters.userId !== undefined) {
            queryParameters['userId'] = requestParameters.userId;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // CustomAuthentication authentication
        }

        const response = await this.request({
            path: `/Playlists/{playlistId}/Items`.replace(`{${"playlistId"}}`, encodeURIComponent(String(requestParameters.playlistId))),
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Adds items to a playlist.
     */
    async addToPlaylist(requestParameters: AddToPlaylistRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.addToPlaylistRaw(requestParameters, initOverrides);
    }

    /**
     * For backwards compatibility parameters can be sent via Query or Body, with Query having higher precedence.  Query parameters are obsolete.
     * Creates a new playlist.
     */
    async createPlaylistRaw(requestParameters: CreatePlaylistOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PlaylistCreationResult>> {
        const queryParameters: any = {};

        if (requestParameters.name !== undefined) {
            queryParameters['name'] = requestParameters.name;
        }

        if (requestParameters.ids) {
            queryParameters['ids'] = requestParameters.ids;
        }

        if (requestParameters.userId !== undefined) {
            queryParameters['userId'] = requestParameters.userId;
        }

        if (requestParameters.mediaType !== undefined) {
            queryParameters['mediaType'] = requestParameters.mediaType;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        headerParameters['Content-Type'] = 'application/json';

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // CustomAuthentication authentication
        }

        const response = await this.request({
            path: `/Playlists`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: CreatePlaylistRequestToJSON(requestParameters.createPlaylistRequest),
        }, initOverrides);

        return new runtime.JSONApiResponse(response, (jsonValue) => PlaylistCreationResultFromJSON(jsonValue));
    }

    /**
     * For backwards compatibility parameters can be sent via Query or Body, with Query having higher precedence.  Query parameters are obsolete.
     * Creates a new playlist.
     */
    async createPlaylist(requestParameters: CreatePlaylistOperationRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PlaylistCreationResult> {
        const response = await this.createPlaylistRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Gets the original items of a playlist.
     */
    async getPlaylistItemsRaw(requestParameters: GetPlaylistItemsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<BaseItemDtoQueryResult>> {
        if (requestParameters.playlistId === null || requestParameters.playlistId === undefined) {
            throw new runtime.RequiredError('playlistId','Required parameter requestParameters.playlistId was null or undefined when calling getPlaylistItems.');
        }

        if (requestParameters.userId === null || requestParameters.userId === undefined) {
            throw new runtime.RequiredError('userId','Required parameter requestParameters.userId was null or undefined when calling getPlaylistItems.');
        }

        const queryParameters: any = {};

        if (requestParameters.userId !== undefined) {
            queryParameters['userId'] = requestParameters.userId;
        }

        if (requestParameters.startIndex !== undefined) {
            queryParameters['startIndex'] = requestParameters.startIndex;
        }

        if (requestParameters.limit !== undefined) {
            queryParameters['limit'] = requestParameters.limit;
        }

        if (requestParameters.fields) {
            queryParameters['fields'] = requestParameters.fields;
        }

        if (requestParameters.enableImages !== undefined) {
            queryParameters['enableImages'] = requestParameters.enableImages;
        }

        if (requestParameters.enableUserData !== undefined) {
            queryParameters['enableUserData'] = requestParameters.enableUserData;
        }

        if (requestParameters.imageTypeLimit !== undefined) {
            queryParameters['imageTypeLimit'] = requestParameters.imageTypeLimit;
        }

        if (requestParameters.enableImageTypes) {
            queryParameters['enableImageTypes'] = requestParameters.enableImageTypes;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // CustomAuthentication authentication
        }

        const response = await this.request({
            path: `/Playlists/{playlistId}/Items`.replace(`{${"playlistId"}}`, encodeURIComponent(String(requestParameters.playlistId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response, (jsonValue) => BaseItemDtoQueryResultFromJSON(jsonValue));
    }

    /**
     * Gets the original items of a playlist.
     */
    async getPlaylistItems(requestParameters: GetPlaylistItemsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<BaseItemDtoQueryResult> {
        const response = await this.getPlaylistItemsRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Moves a playlist item.
     */
    async moveItemRaw(requestParameters: MoveItemRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.playlistId === null || requestParameters.playlistId === undefined) {
            throw new runtime.RequiredError('playlistId','Required parameter requestParameters.playlistId was null or undefined when calling moveItem.');
        }

        if (requestParameters.itemId === null || requestParameters.itemId === undefined) {
            throw new runtime.RequiredError('itemId','Required parameter requestParameters.itemId was null or undefined when calling moveItem.');
        }

        if (requestParameters.newIndex === null || requestParameters.newIndex === undefined) {
            throw new runtime.RequiredError('newIndex','Required parameter requestParameters.newIndex was null or undefined when calling moveItem.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // CustomAuthentication authentication
        }

        const response = await this.request({
            path: `/Playlists/{playlistId}/Items/{itemId}/Move/{newIndex}`.replace(`{${"playlistId"}}`, encodeURIComponent(String(requestParameters.playlistId))).replace(`{${"itemId"}}`, encodeURIComponent(String(requestParameters.itemId))).replace(`{${"newIndex"}}`, encodeURIComponent(String(requestParameters.newIndex))),
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Moves a playlist item.
     */
    async moveItem(requestParameters: MoveItemRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.moveItemRaw(requestParameters, initOverrides);
    }

    /**
     * Removes items from a playlist.
     */
    async removeFromPlaylistRaw(requestParameters: RemoveFromPlaylistRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.playlistId === null || requestParameters.playlistId === undefined) {
            throw new runtime.RequiredError('playlistId','Required parameter requestParameters.playlistId was null or undefined when calling removeFromPlaylist.');
        }

        const queryParameters: any = {};

        if (requestParameters.entryIds) {
            queryParameters['entryIds'] = requestParameters.entryIds;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // CustomAuthentication authentication
        }

        const response = await this.request({
            path: `/Playlists/{playlistId}/Items`.replace(`{${"playlistId"}}`, encodeURIComponent(String(requestParameters.playlistId))),
            method: 'DELETE',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Removes items from a playlist.
     */
    async removeFromPlaylist(requestParameters: RemoveFromPlaylistRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.removeFromPlaylistRaw(requestParameters, initOverrides);
    }

}
