import { ThreadListRuntimeCore } from "../core/ThreadListRuntimeCore";
import { BaseSubscribable } from "../remote-thread-list/BaseSubscribable";
import { LocalThreadRuntimeCore } from "./LocalThreadRuntimeCore";

export type LocalThreadFactory = () => LocalThreadRuntimeCore;

const EMPTY_ARRAY = Object.freeze([]);
const DEFAULT_THREAD_ID = "__DEFAULT_ID__";
const DEFAULT_THREAD_DATA = Object.freeze({
  [DEFAULT_THREAD_ID]: {
    id: DEFAULT_THREAD_ID,
    remoteId: undefined,
    externalId: undefined,
    status: "regular" as const,
    title: undefined,
  },
});
export class LocalThreadListRuntimeCore
  extends BaseSubscribable
  implements ThreadListRuntimeCore
{
  private _mainThread: LocalThreadRuntimeCore;
  constructor(_threadFactory: LocalThreadFactory) {
    super();

    this._mainThread = _threadFactory();
  }

  public get isLoading() {
    return false;
  }

  public getMainThreadRuntimeCore() {
    return this._mainThread;
  }

  public get newThreadId(): string {
    throw new Error("Method not implemented.");
  }

  public get threadIds(): readonly string[] {
    throw EMPTY_ARRAY;
  }

  public get archivedThreadIds(): readonly string[] {
    throw EMPTY_ARRAY;
  }

  public get mainThreadId(): string {
    return DEFAULT_THREAD_ID;
  }

  public get threadData() {
    return DEFAULT_THREAD_DATA;
  }

  public getThreadRuntimeCore(): never {
    throw new Error("Method not implemented.");
  }

  public getLoadThreadsPromise(): Promise<void> {
    throw new Error("Method not implemented.");
  }

  public getItemById(threadId: string) {
    if (threadId === this.mainThreadId) {
      return {
        status: "regular" as const,
        id: this.mainThreadId,
        remoteId: this.mainThreadId,
        externalId: undefined,
        title: undefined,
        isMain: true,
      };
    }
    throw new Error("Method not implemented");
  }

  public async switchToThread(): Promise<void> {
    throw new Error("Method not implemented.");
  }

  public switchToNewThread(): Promise<void> {
    throw new Error("Method not implemented.");
  }

  public rename(): Promise<void> {
    throw new Error("Method not implemented.");
  }

  public archive(): Promise<void> {
    throw new Error("Method not implemented.");
  }

  public detach(): Promise<void> {
    throw new Error("Method not implemented.");
  }

  public unarchive(): Promise<void> {
    throw new Error("Method not implemented.");
  }

  public delete(): Promise<void> {
    throw new Error("Method not implemented.");
  }

  public initialize(): never {
    throw new Error("Method not implemented.");
  }

  public generateTitle(): never {
    throw new Error("Method not implemented.");
  }
}
