/* tslint:disable */
/* eslint-disable */
/**
 * Commander Spellbook API
 * API for Commander Spellbook, the combo database engine for Magic: The Gathering
 *
 * The version of the OpenAPI document: 4.2.2
 * 
 *
 * 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 {
  PaginatedWebsitePropertyList,
  WebsiteProperty,
} from '../models/index';
import {
    PaginatedWebsitePropertyListFromJSON,
    PaginatedWebsitePropertyListToJSON,
    WebsitePropertyFromJSON,
    WebsitePropertyToJSON,
} from '../models/index';

export interface PropertiesListRequest {
    limit?: number;
    offset?: number;
}

export interface PropertiesRetrieveRequest {
    key: string;
}

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

    /**
     */
    async propertiesListRaw(requestParameters: PropertiesListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PaginatedWebsitePropertyList>> {
        const queryParameters: any = {};

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

        if (requestParameters['offset'] != null) {
            queryParameters['offset'] = requestParameters['offset'];
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("jwtAuth", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }
        const response = await this.request({
            path: `/properties/`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async propertiesList(requestParameters: PropertiesListRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PaginatedWebsitePropertyList> {
        const response = await this.propertiesListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async propertiesRetrieveRaw(requestParameters: PropertiesRetrieveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<WebsiteProperty>> {
        if (requestParameters['key'] == null) {
            throw new runtime.RequiredError(
                'key',
                'Required parameter "key" was null or undefined when calling propertiesRetrieve().'
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("jwtAuth", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }
        const response = await this.request({
            path: `/properties/{key}/`.replace(`{${"key"}}`, encodeURIComponent(String(requestParameters['key']))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async propertiesRetrieve(requestParameters: PropertiesRetrieveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<WebsiteProperty> {
        const response = await this.propertiesRetrieveRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
