/* 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 {
  CartAdd,
  CartDetail,
  CartItemEdit,
  CashOut,
  CashOutGatewayResponse,
  CashOutSuccessResponse,
} from '../models';

export interface ApiShoppingcartV1CartAddCreateRequest {
    data: CartAdd;
}

export interface ApiShoppingcartV1CartClearCreateRequest {
    cartId: string;
}

export interface ApiShoppingcartV1CartEditPartialUpdateRequest {
    data: CartItemEdit;
}

export interface ApiShoppingcartV1CartReadRequest {
    cartId: string;
}

export interface ApiShoppingcartV1CartRemoveDeleteRequest {
    itemId: string;
}

export interface ApiShoppingcartV1CashOutCreateRequest {
    data: CashOut;
}

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

    /**
     *  - Adds a product variant to the cart. - If a cart for the shop doesn\'t exist, it will be created. - Prevents adding more than the available stock of the variant. 
     * Add item to cart
     */
    async apiShoppingcartV1CartAddCreateRaw(requestParameters: ApiShoppingcartV1CartAddCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.data === null || requestParameters.data === undefined) {
            throw new runtime.RequiredError('data','Required parameter requestParameters.data was null or undefined when calling apiShoppingcartV1CartAddCreate.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

        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/shoppingcart/v1/cart/add/`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: requestParameters.data,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     *  - Adds a product variant to the cart. - If a cart for the shop doesn\'t exist, it will be created. - Prevents adding more than the available stock of the variant. 
     * Add item to cart
     */
    async apiShoppingcartV1CartAddCreate(requestParameters: ApiShoppingcartV1CartAddCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiShoppingcartV1CartAddCreateRaw(requestParameters, initOverrides);
    }

    /**
     * Deletes the entire cart (and its items) using the cart UUID.
     * Delete a specific cart
     */
    async apiShoppingcartV1CartClearCreateRaw(requestParameters: ApiShoppingcartV1CartClearCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.cartId === null || requestParameters.cartId === undefined) {
            throw new runtime.RequiredError('cartId','Required parameter requestParameters.cartId was null or undefined when calling apiShoppingcartV1CartClearCreate.');
        }

        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 response = await this.request({
            path: `/api/shoppingcart/v1/cart/clear/{cart_id}`.replace(`{${"cart_id"}}`, encodeURIComponent(String(requestParameters.cartId))),
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Deletes the entire cart (and its items) using the cart UUID.
     * Delete a specific cart
     */
    async apiShoppingcartV1CartClearCreate(requestParameters: ApiShoppingcartV1CartClearCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiShoppingcartV1CartClearCreateRaw(requestParameters, initOverrides);
    }

    /**
     *  Updates the quantity of a product in the user\'s cart. Requires the `item_id` and the new `quantity` in the request body. 
     * Edit cart item quantity
     */
    async apiShoppingcartV1CartEditPartialUpdateRaw(requestParameters: ApiShoppingcartV1CartEditPartialUpdateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.data === null || requestParameters.data === undefined) {
            throw new runtime.RequiredError('data','Required parameter requestParameters.data was null or undefined when calling apiShoppingcartV1CartEditPartialUpdate.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

        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/shoppingcart/v1/cart/edit/`,
            method: 'PATCH',
            headers: headerParameters,
            query: queryParameters,
            body: requestParameters.data,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     *  Updates the quantity of a product in the user\'s cart. Requires the `item_id` and the new `quantity` in the request body. 
     * Edit cart item quantity
     */
    async apiShoppingcartV1CartEditPartialUpdate(requestParameters: ApiShoppingcartV1CartEditPartialUpdateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiShoppingcartV1CartEditPartialUpdateRaw(requestParameters, initOverrides);
    }

    /**
     * Returns all active carts (not checked out) for the current user.
     * Get all carts for the user
     */
    async apiShoppingcartV1CartListRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<CartDetail>>> {
        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 response = await this.request({
            path: `/api/shoppingcart/v1/cart/`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Returns all active carts (not checked out) for the current user.
     * Get all carts for the user
     */
    async apiShoppingcartV1CartList(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<CartDetail>> {
        const response = await this.apiShoppingcartV1CartListRaw(initOverrides);
        return await response.value();
    }

    /**
     * Returns the detail of a specific cart, including its items.
     * Get specific cart details
     */
    async apiShoppingcartV1CartReadRaw(requestParameters: ApiShoppingcartV1CartReadRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<CartDetail>> {
        if (requestParameters.cartId === null || requestParameters.cartId === undefined) {
            throw new runtime.RequiredError('cartId','Required parameter requestParameters.cartId was null or undefined when calling apiShoppingcartV1CartRead.');
        }

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

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Returns the detail of a specific cart, including its items.
     * Get specific cart details
     */
    async apiShoppingcartV1CartRead(requestParameters: ApiShoppingcartV1CartReadRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<CartDetail> {
        const response = await this.apiShoppingcartV1CartReadRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Removes a specific cart item by ID. Deletes the cart if it becomes empty.
     * Remove item from cart
     */
    async apiShoppingcartV1CartRemoveDeleteRaw(requestParameters: ApiShoppingcartV1CartRemoveDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.itemId === null || requestParameters.itemId === undefined) {
            throw new runtime.RequiredError('itemId','Required parameter requestParameters.itemId was null or undefined when calling apiShoppingcartV1CartRemoveDelete.');
        }

        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 response = await this.request({
            path: `/api/shoppingcart/v1/cart/remove/{item_id}/`.replace(`{${"item_id"}}`, encodeURIComponent(String(requestParameters.itemId))),
            method: 'DELETE',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Removes a specific cart item by ID. Deletes the cart if it becomes empty.
     * Remove item from cart
     */
    async apiShoppingcartV1CartRemoveDelete(requestParameters: ApiShoppingcartV1CartRemoveDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiShoppingcartV1CartRemoveDeleteRaw(requestParameters, initOverrides);
    }

    /**
     *  Creates an order from the user\'s shopping cart. - If wallet balance is sufficient → pay directly from wallet. - Otherwise → redirect user to Zarinpal payment gateway. 
     * Submit order and handle payment
     */
    async apiShoppingcartV1CashOutCreateRaw(requestParameters: ApiShoppingcartV1CashOutCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<CashOutGatewayResponse>> {
        if (requestParameters.data === null || requestParameters.data === undefined) {
            throw new runtime.RequiredError('data','Required parameter requestParameters.data was null or undefined when calling apiShoppingcartV1CashOutCreate.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

        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/shoppingcart/v1/cash-out/`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: requestParameters.data,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     *  Creates an order from the user\'s shopping cart. - If wallet balance is sufficient → pay directly from wallet. - Otherwise → redirect user to Zarinpal payment gateway. 
     * Submit order and handle payment
     */
    async apiShoppingcartV1CashOutCreate(requestParameters: ApiShoppingcartV1CashOutCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<CashOutGatewayResponse> {
        const response = await this.apiShoppingcartV1CashOutCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
