/* 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 {
  ApiCommentV1CommentList200Response,
  ApiCommentV1VerifyCommentList200Response,
  ProductComment,
  ProductReview,
  ProductReviewStats,
} from '../models';

export interface ApiCommentV1CommentCreateRequest {
    data: ProductComment;
}

export interface ApiCommentV1CommentListRequest {
    productId: string;
    page?: number;
    pageSize?: number;
}

export interface ApiCommentV1ReviewCreateRequest {
    data: ProductReview;
}

export interface ApiCommentV1ReviewListRequest {
    productId: string;
}

export interface ApiCommentV1VerifyCommentListRequest {
    productId: string;
}

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

    /**
     *  - Buyers can post a **new comment** (no parent) on a product if they have purchased it. - Only the **seller of the product** or **superadmins** can reply to a comment (with parent). 
     * Post a product comment or reply
     */
    async apiCommentV1CommentCreateRaw(requestParameters: ApiCommentV1CommentCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ProductComment>> {
        if (requestParameters.data === null || requestParameters.data === undefined) {
            throw new runtime.RequiredError('data','Required parameter requestParameters.data was null or undefined when calling apiCommentV1CommentCreate.');
        }

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

        return new runtime.JSONApiResponse(response);
    }

    /**
     *  - Buyers can post a **new comment** (no parent) on a product if they have purchased it. - Only the **seller of the product** or **superadmins** can reply to a comment (with parent). 
     * Post a product comment or reply
     */
    async apiCommentV1CommentCreate(requestParameters: ApiCommentV1CommentCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ProductComment> {
        const response = await this.apiCommentV1CommentCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Get product comments with ratings and replies
     */
    async apiCommentV1CommentListRaw(requestParameters: ApiCommentV1CommentListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ApiCommentV1CommentList200Response>> {
        if (requestParameters.productId === null || requestParameters.productId === undefined) {
            throw new runtime.RequiredError('productId','Required parameter requestParameters.productId was null or undefined when calling apiCommentV1CommentList.');
        }

        const queryParameters: any = {};

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

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

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

        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/comment/v1/comment/`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Get product comments with ratings and replies
     */
    async apiCommentV1CommentList(requestParameters: ApiCommentV1CommentListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ApiCommentV1CommentList200Response> {
        const response = await this.apiCommentV1CommentListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     *  - Creates a new review if not already exists. - Updates the review if one exists. - Only one review per (user, product). - User must have purchased the product. 
     * Create or Update a Product Review
     */
    async apiCommentV1ReviewCreateRaw(requestParameters: ApiCommentV1ReviewCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ProductReview>> {
        if (requestParameters.data === null || requestParameters.data === undefined) {
            throw new runtime.RequiredError('data','Required parameter requestParameters.data was null or undefined when calling apiCommentV1ReviewCreate.');
        }

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

        return new runtime.JSONApiResponse(response);
    }

    /**
     *  - Creates a new review if not already exists. - Updates the review if one exists. - Only one review per (user, product). - User must have purchased the product. 
     * Create or Update a Product Review
     */
    async apiCommentV1ReviewCreate(requestParameters: ApiCommentV1ReviewCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ProductReview> {
        const response = await this.apiCommentV1ReviewCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Handles creating/updating product reviews (POST) and retrieving average rating (GET).
     * Get average review rating for a product
     */
    async apiCommentV1ReviewListRaw(requestParameters: ApiCommentV1ReviewListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ProductReviewStats>> {
        if (requestParameters.productId === null || requestParameters.productId === undefined) {
            throw new runtime.RequiredError('productId','Required parameter requestParameters.productId was null or undefined when calling apiCommentV1ReviewList.');
        }

        const queryParameters: any = {};

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

        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/comment/v1/review/`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Handles creating/updating product reviews (POST) and retrieving average rating (GET).
     * Get average review rating for a product
     */
    async apiCommentV1ReviewList(requestParameters: ApiCommentV1ReviewListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ProductReviewStats> {
        const response = await this.apiCommentV1ReviewListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Check if user can comment on a product
     */
    async apiCommentV1VerifyCommentListRaw(requestParameters: ApiCommentV1VerifyCommentListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ApiCommentV1VerifyCommentList200Response>> {
        if (requestParameters.productId === null || requestParameters.productId === undefined) {
            throw new runtime.RequiredError('productId','Required parameter requestParameters.productId was null or undefined when calling apiCommentV1VerifyCommentList.');
        }

        const queryParameters: any = {};

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

        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/comment/v1/verify-comment/`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Check if user can comment on a product
     */
    async apiCommentV1VerifyCommentList(requestParameters: ApiCommentV1VerifyCommentListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ApiCommentV1VerifyCommentList200Response> {
        const response = await this.apiCommentV1VerifyCommentListRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
