// File: monorepo/web/maplefile-frontend/src/services/API/Tag/DeleteTagAPIService.js
// Delete Tag API Service - Handles tag deletion

class DeleteTagAPIService {
  constructor(authManager) {
    this.authManager = authManager;
    this._apiClient = null;
    console.log(
      "[DeleteTagAPIService] API service initialized with AuthManager dependency",
    );
  }

  // Import ApiClient for authenticated requests
  async getApiClient() {
    if (!this._apiClient) {
      const { default: ApiClient } = await import("../ApiClient.js");
      this._apiClient = ApiClient;
    }
    return this._apiClient;
  }

  // Delete tag via API
  async deleteTag(tagId) {
    try {
      console.log("[DeleteTagAPIService] Deleting tag via API:", tagId);

      if (!tagId) {
        throw new Error("Tag ID is required for deletion");
      }

      const apiClient = await this.getApiClient();
      const response = await apiClient.deleteMapleFile(`/tags/${tagId}`);

      console.log("[DeleteTagAPIService] Tag deleted successfully");
      return response;
    } catch (error) {
      console.error("[DeleteTagAPIService] Tag deletion failed:", error);
      throw error;
    }
  }

  // Get debug information
  getDebugInfo() {
    return {
      serviceName: "DeleteTagAPIService",
      managedBy: "AuthManager",
      isAuthenticated: this.authManager.isAuthenticated(),
      canMakeRequests: this.authManager.canMakeAuthenticatedRequests(),
    };
  }
}

export default DeleteTagAPIService;
