import { type LocationSample, type LocationSource, type LocationSourceCallbacks } from './locationSource'

export class MockLocationSource implements LocationSource {
  callbacks: LocationSourceCallbacks
  active: boolean
  lastSample: LocationSample | null

  constructor(callbacks: LocationSourceCallbacks) {
    this.callbacks = callbacks
    this.active = false
    this.lastSample = null
  }

  get mode(): 'mock' {
    return 'mock'
  }

  start(): void {
    if (this.active) {
      this.callbacks.onStatus('模拟定位进行中')
      return
    }

    this.active = true
    this.callbacks.onStatus('模拟定位已启动，等待外部输入')
  }

  stop(): void {
    if (!this.active) {
      this.callbacks.onStatus('模拟定位未启动')
      return
    }

    this.active = false
    this.callbacks.onStatus('模拟定位已停止')
  }

  destroy(): void {
    this.active = false
    this.lastSample = null
  }

  pushSample(sample: LocationSample): void {
    this.lastSample = sample
    if (!this.active) {
      return
    }

    this.callbacks.onLocation(sample)
  }
}
