import { FileWriteData } from '../workbench/Workbench'
import {
  FILE_WRITE,
  MULTIPLE_FILE_WRITE,
  ElementHighlightMessageType,
  FRONTEND_FILE_WRITE,
  GENERATE_GRAPHQL,
  SAVE_ZIP,
} from './messageTypes'
import IMessaging from './messaging'

export class FrontendActions {
  constructor(messagingService: IMessaging) {
    this.messagingService = messagingService
  }

  private messagingService: IMessaging

  saveZip() {
    this.messagingService.postMessage(SAVE_ZIP, {})
  }

  fileWrite(path: string, data: string) {
    this.messagingService.postMessage<FileWriteData>(FILE_WRITE, { path, data })
  }

  multipleFileWrite(files: FileWriteData[]) {
    this.messagingService.postMessage<FileWriteData[]>(
      MULTIPLE_FILE_WRITE,
      files
    )
  }
  frontendFileWrite(path: string, data: string) {
    this.messagingService.postMessage<FileWriteData>(FRONTEND_FILE_WRITE, {
      path,
      data,
    })
  }

  elementHighlightClick<SourceLineCol>(
    type: ElementHighlightMessageType,
    source: SourceLineCol
  ) {
    this.messagingService.postMessage(type, source)
  }

  generateGraphql() {
    this.messagingService.postMessage(GENERATE_GRAPHQL, {})
  }
}
