"use strict";

/**
 * Developer API Methods Mixin
 * 
 * Provides methods for managing developer applications and API keys
 */

import { CACHE_TIMES } from './mixinHelpers';
export function OxyServicesDeveloperMixin(Base) {
  return class extends Base {
    constructor(...args) {
      super(...args);
    }

    /**
     * Get developer apps for the current user
     * @returns Array of developer apps
     */
    async getDeveloperApps() {
      try {
        const res = await this.makeRequest('GET', '/api/developer/apps', undefined, {
          cache: true,
          cacheTTL: CACHE_TIMES.MEDIUM
        });
        return res.apps || [];
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Create a new developer app
     * @param data - Developer app configuration
     * @returns Created developer app
     */
    async createDeveloperApp(data) {
      try {
        const res = await this.makeRequest('POST', '/api/developer/apps', data, {
          cache: false
        });
        return res.app;
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Get a specific developer app
     */
    async getDeveloperApp(appId) {
      try {
        const res = await this.makeRequest('GET', `/api/developer/apps/${appId}`, undefined, {
          cache: true,
          cacheTTL: CACHE_TIMES.LONG
        });
        return res.app;
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Update a developer app
     * @param appId - The developer app ID
     * @param data - Updated app configuration
     * @returns Updated developer app
     */
    async updateDeveloperApp(appId, data) {
      try {
        const res = await this.makeRequest('PATCH', `/api/developer/apps/${appId}`, data, {
          cache: false
        });
        return res.app;
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Regenerate API secret for a developer app
     * @param appId - The developer app ID
     * @returns App with new secret
     */
    async regenerateDeveloperAppSecret(appId) {
      try {
        return await this.makeRequest('POST', `/api/developer/apps/${appId}/regenerate-secret`, undefined, {
          cache: false
        });
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Delete a developer app
     * @param appId - The developer app ID
     * @returns Deletion result
     */
    async deleteDeveloperApp(appId) {
      try {
        return await this.makeRequest('DELETE', `/api/developer/apps/${appId}`, undefined, {
          cache: false
        });
      } catch (error) {
        throw this.handleError(error);
      }
    }
  };
}
//# sourceMappingURL=OxyServices.developer.js.map