/* 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 {
  NotificationCreate,
  NotificationList,
  NotificationMarkRead,
  PreferenceUpsert,
} from '../models';

export interface ApiNotifV1NotificationsCreateRequest {
    xSERVICEKEY: string;
    data: NotificationCreate;
}

export interface ApiNotifV1NotificationsListRequest {
    page?: number;
    pageSize?: number;
    read?: boolean;
    type?: string;
}

export interface ApiNotifV1NotificationsPreferencesCreateRequest {
    data: PreferenceUpsert;
}

export interface ApiNotifV1NotificationsReadPartialUpdateRequest {
    id: string;
    data: NotificationMarkRead;
}

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

    /**
     * Requires a valid X-SERVICE-KEY header. Renders SMS from NotificationType.template using declared variables, creates a Notification row, and sends SMS immediately.
     * Create notification and send SMS now (service-only)
     */
    async apiNotifV1NotificationsCreateRaw(requestParameters: ApiNotifV1NotificationsCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<NotificationCreate>> {
        if (requestParameters.xSERVICEKEY === null || requestParameters.xSERVICEKEY === undefined) {
            throw new runtime.RequiredError('xSERVICEKEY','Required parameter requestParameters.xSERVICEKEY was null or undefined when calling apiNotifV1NotificationsCreate.');
        }

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

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

        if (requestParameters.xSERVICEKEY !== undefined && requestParameters.xSERVICEKEY !== null) {
            headerParameters['X-SERVICE-KEY'] = String(requestParameters.xSERVICEKEY);
        }

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

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Requires a valid X-SERVICE-KEY header. Renders SMS from NotificationType.template using declared variables, creates a Notification row, and sends SMS immediately.
     * Create notification and send SMS now (service-only)
     */
    async apiNotifV1NotificationsCreate(requestParameters: ApiNotifV1NotificationsCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<NotificationCreate> {
        const response = await this.apiNotifV1NotificationsCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Returns notifications for the authenticated user. Filters: ?read=true|false, ?type=code
     * List in-app notifications
     */
    async apiNotifV1NotificationsListRaw(requestParameters: ApiNotifV1NotificationsListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<NotificationList>>> {
        const queryParameters: any = {};

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

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

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

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

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

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Returns notifications for the authenticated user. Filters: ?read=true|false, ?type=code
     * List in-app notifications
     */
    async apiNotifV1NotificationsList(requestParameters: ApiNotifV1NotificationsListRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<NotificationList>> {
        const response = await this.apiNotifV1NotificationsListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Create or update a user preference (allow_sms / allow_in_app) for the given type_code.
     * Set notification preference
     */
    async apiNotifV1NotificationsPreferencesCreateRaw(requestParameters: ApiNotifV1NotificationsPreferencesCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PreferenceUpsert>> {
        if (requestParameters.data === null || requestParameters.data === undefined) {
            throw new runtime.RequiredError('data','Required parameter requestParameters.data was null or undefined when calling apiNotifV1NotificationsPreferencesCreate.');
        }

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

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Create or update a user preference (allow_sms / allow_in_app) for the given type_code.
     * Set notification preference
     */
    async apiNotifV1NotificationsPreferencesCreate(requestParameters: ApiNotifV1NotificationsPreferencesCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PreferenceUpsert> {
        const response = await this.apiNotifV1NotificationsPreferencesCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Sets read=True if the notification belongs to the authenticated user.
     * Mark a notification as read
     */
    async apiNotifV1NotificationsReadPartialUpdateRaw(requestParameters: ApiNotifV1NotificationsReadPartialUpdateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters.id === null || requestParameters.id === undefined) {
            throw new runtime.RequiredError('id','Required parameter requestParameters.id was null or undefined when calling apiNotifV1NotificationsReadPartialUpdate.');
        }

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

        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/notif/v1/notifications/{id}/read/`.replace(`{${"id"}}`, encodeURIComponent(String(requestParameters.id))),
            method: 'PATCH',
            headers: headerParameters,
            query: queryParameters,
            body: requestParameters.data,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Sets read=True if the notification belongs to the authenticated user.
     * Mark a notification as read
     */
    async apiNotifV1NotificationsReadPartialUpdate(requestParameters: ApiNotifV1NotificationsReadPartialUpdateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiNotifV1NotificationsReadPartialUpdateRaw(requestParameters, initOverrides);
    }

}
