/* tslint:disable */
/* eslint-disable */
/**
 * Vitron API
 * API documentation for Vitron backend
 *
 * The version of the OpenAPI document: v1
 * Contact: support@yourcompany.com
 *
 * 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 {
  ImageUploadResponse,
} from '../models';

export interface ApiMediaV1ImageResizeListRequest {
    imageId: string;
    width?: number;
    height?: number;
    scale?: number;
}

export interface ApiMediaV1MediaResizeReadRequest {
    filePath: string;
    width?: number;
    height?: number;
    scale?: number;
}

export interface MediaUploadImageRequest {
    file: Blob;
    usage: MediaUploadImageUsageEnum;
}

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

    /**
     * Resize image using either width+height percentages or a single scale percentage.
     * Get resized image (percent or scale)
     */
    async apiMediaV1ImageResizeListRaw(requestParameters: ApiMediaV1ImageResizeListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.imageId === null || requestParameters.imageId === undefined) {
            throw new runtime.RequiredError('imageId','Required parameter requestParameters.imageId was null or undefined when calling apiMediaV1ImageResizeList.');
        }

        const queryParameters: any = {};

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

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

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

        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);
        }
        const response = await this.request({
            path: `/api/media/v1/image/{image_id}/resize/`.replace(`{${"image_id"}}`, encodeURIComponent(String(requestParameters.imageId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Resize image using either width+height percentages or a single scale percentage.
     * Get resized image (percent or scale)
     */
    async apiMediaV1ImageResizeList(requestParameters: ApiMediaV1ImageResizeListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiMediaV1ImageResizeListRaw(requestParameters, initOverrides);
    }

    /**
     * Resize and serve an image by file path using either width+height percentages or a scale. Example: `/media-resize/uploads/image.jpg?scale=70` or `?width=80&height=40`
     * Resize image by file path (percent or scale)
     */
    async apiMediaV1MediaResizeReadRaw(requestParameters: ApiMediaV1MediaResizeReadRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.filePath === null || requestParameters.filePath === undefined) {
            throw new runtime.RequiredError('filePath','Required parameter requestParameters.filePath was null or undefined when calling apiMediaV1MediaResizeRead.');
        }

        const queryParameters: any = {};

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

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

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

        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);
        }
        const response = await this.request({
            path: `/api/media/v1/media-resize/{file_path}`.replace(`{${"file_path"}}`, encodeURIComponent(String(requestParameters.filePath))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Resize and serve an image by file path using either width+height percentages or a scale. Example: `/media-resize/uploads/image.jpg?scale=70` or `?width=80&height=40`
     * Resize image by file path (percent or scale)
     */
    async apiMediaV1MediaResizeRead(requestParameters: ApiMediaV1MediaResizeReadRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiMediaV1MediaResizeReadRaw(requestParameters, initOverrides);
    }

    /**
     * Upload an image and specify usage: product | logo | profile | banner
     * Upload image
     */
    async mediaUploadImageRaw(requestParameters: MediaUploadImageRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ImageUploadResponse>> {
        if (requestParameters.file === null || requestParameters.file === undefined) {
            throw new runtime.RequiredError('file','Required parameter requestParameters.file was null or undefined when calling mediaUploadImage.');
        }

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

        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);
        }
        const consumes: runtime.Consume[] = [
            { contentType: 'multipart/form-data' },
            { contentType: 'application/x-www-form-urlencoded' },
        ];
        // @ts-ignore: canConsumeForm may be unused
        const canConsumeForm = runtime.canConsumeForm(consumes);

        let formParams: { append(param: string, value: any): any };
        let useForm = false;
        // use FormData to transmit files using content-type "multipart/form-data"
        useForm = canConsumeForm;
        if (useForm) {
            formParams = new FormData();
        } else {
            formParams = new URLSearchParams();
        }

        if (requestParameters.file !== undefined) {
            formParams.append('file', requestParameters.file as any);
        }

        if (requestParameters.usage !== undefined) {
            formParams.append('usage', requestParameters.usage as any);
        }

        const response = await this.request({
            path: `/api/media/v1/image/`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: formParams,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Upload an image and specify usage: product | logo | profile | banner
     * Upload image
     */
    async mediaUploadImage(requestParameters: MediaUploadImageRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ImageUploadResponse> {
        const response = await this.mediaUploadImageRaw(requestParameters, initOverrides);
        return await response.value();
    }

}

/**
 * @export
 */
export const MediaUploadImageUsageEnum = {
    Product: 'product',
    Logo: 'logo',
    Profile: 'profile',
    Banner: 'banner'
} as const;
export type MediaUploadImageUsageEnum = typeof MediaUploadImageUsageEnum[keyof typeof MediaUploadImageUsageEnum];
