import {defineStore} from 'pinia'
import WsRequest from "@/api/WsRequest";
import type Message from "@/mode/Message";
import type Receipt from "@/mode/Receipt";


export const useWsStore = defineStore({
  id: 'online_store',
  state: () => ({
    wsRequest: WsRequest.getInstance(),
  }),

  actions: {
    init(): void {
      this.wsRequest.init()
    },
    reconnect(): void {
      this.wsRequest.reconnect()
    },
    reset(): void {
      this.wsRequest.reset()
    },
    send(str: string): void {
      this.wsRequest.send(str)
    },
    close(closeByUser:boolean): void {
      this.wsRequest.close(closeByUser)
    },
    sendMessage(message: Message): void {
      this.wsRequest.sendMessage(message)
    },
    sendRead(receipt: Receipt): void {
      this.wsRequest.sendRead(receipt)
    },
    callBack(callback:() => void): void {
      this.wsRequest.callback = callback
    },
    checkStatus(): void {
      this.wsRequest.checkStatus()
    }
  }
})
