import {
  ImageResult,
  PlatformService,
  PlatformCapabilities,
} from "../PlatformService";
import { logger } from "../../utils/logger";
import { QueryExecResult } from "@/interfaces/database";

/**
 * Platform service implementation for PyWebView platform.
 * Note: This is a placeholder implementation with most methods currently unimplemented.
 * Implements the PlatformService interface but throws "Not implemented" errors for most operations.
 *
 * @remarks
 * This service is intended for Python-based desktop applications using pywebview.
 * Future implementations should provide:
 * - Integration with Python backend file operations
 * - System camera access through Python
 * - Native system dialogs via pywebview
 * - Python-JavaScript bridge functionality
 */
export class PyWebViewPlatformService implements PlatformService {
  /**
   * Gets the capabilities of the PyWebView platform
   * @returns Platform capabilities object
   */
  getCapabilities(): PlatformCapabilities {
    return {
      hasFileSystem: false, // Not implemented yet
      hasCamera: false, // Not implemented yet
      isMobile: false,
      isIOS: false,
      hasFileDownload: false, // Not implemented yet
      needsFileHandlingInstructions: false,
    };
  }

  /**
   * Reads a file using the Python backend.
   * @param _path - Path to the file to read
   * @returns Promise that should resolve to file contents
   * @throws Error with "Not implemented" message
   * @todo Implement file reading through pywebview's Python-JavaScript bridge
   */
  async readFile(_path: string): Promise<string> {
    throw new Error("Not implemented");
  }

  /**
   * Writes content to a file using the Python backend.
   * @param _path - Path where to write the file
   * @param _content - Content to write to the file
   * @throws Error with "Not implemented" message
   * @todo Implement file writing through pywebview's Python-JavaScript bridge
   */
  async writeFile(_path: string, _content: string): Promise<void> {
    throw new Error("Not implemented");
  }

  /**
   * Deletes a file using the Python backend.
   * @param _path - Path to the file to delete
   * @throws Error with "Not implemented" message
   * @todo Implement file deletion through pywebview's Python-JavaScript bridge
   */
  async deleteFile(_path: string): Promise<void> {
    throw new Error("Not implemented");
  }

  /**
   * Lists files in the specified directory using the Python backend.
   * @param _directory - Path to the directory to list
   * @returns Promise that should resolve to array of filenames
   * @throws Error with "Not implemented" message
   * @todo Implement directory listing through pywebview's Python-JavaScript bridge
   */
  async listFiles(_directory: string): Promise<string[]> {
    throw new Error("Not implemented");
  }

  /**
   * Should open system camera through Python backend.
   * @returns Promise that should resolve to captured image data
   * @throws Error with "Not implemented" message
   * @todo Implement camera access using Python's camera libraries
   */
  async takePicture(): Promise<ImageResult> {
    logger.error("takePicture not implemented in PyWebView platform");
    throw new Error("Not implemented");
  }

  /**
   * Should open system file picker through pywebview.
   * @returns Promise that should resolve to selected image data
   * @throws Error with "Not implemented" message
   * @todo Implement file picker using pywebview's file dialog API
   */
  async pickImage(): Promise<ImageResult> {
    logger.error("pickImage not implemented in PyWebView platform");
    throw new Error("Not implemented");
  }

  /**
   * Should handle deep link URLs through the Python backend.
   * @param _url - The deep link URL to handle
   * @throws Error with "Not implemented" message
   * @todo Implement deep link handling using Python's URL handling capabilities
   */
  async handleDeepLink(_url: string): Promise<void> {
    logger.error("handleDeepLink not implemented in PyWebView platform");
    throw new Error("Not implemented");
  }

  dbQuery(sql: string, params?: unknown[]): Promise<QueryExecResult> {
    throw new Error("Not implemented for " + sql + " with params " + params);
  }
  dbExec(
    sql: string,
    params?: unknown[],
  ): Promise<{ changes: number; lastId?: number }> {
    throw new Error("Not implemented for " + sql + " with params " + params);
  }

  /**
   * Should write and share a file using the Python backend.
   * @param _fileName - Name of the file to write and share
   * @param _content - Content to write to the file
   * @throws Error with "Not implemented" message
   * @todo Implement file writing and sharing through pywebview's Python-JavaScript bridge
   */
  async writeAndShareFile(_fileName: string, _content: string): Promise<void> {
    logger.error("writeAndShareFile not implemented in PyWebView platform");
    throw new Error("Not implemented");
  }
}
