import * as plugins from '../../plugins.js';
import { DcRouterDb } from '../classes.dcrouter-db.js';
import type { IRemoteIngressPerformanceConfig } from '../../../ts_interfaces/data/remoteingress.js';

const getDb = () => DcRouterDb.getInstance().getDb();

@plugins.smartdata.Collection(() => getDb())
export class RemoteIngressEdgeDoc extends plugins.smartdata.SmartDataDbDoc<RemoteIngressEdgeDoc, RemoteIngressEdgeDoc> {
  @plugins.smartdata.unI()
  @plugins.smartdata.svDb()
  public id!: string;

  @plugins.smartdata.svDb()
  public name: string = '';

  @plugins.smartdata.svDb()
  public secret!: string;

  @plugins.smartdata.svDb()
  public listenPorts!: number[];

  @plugins.smartdata.svDb()
  public listenPortsUdp!: number[];

  @plugins.smartdata.svDb()
  public enabled!: boolean;

  @plugins.smartdata.svDb()
  public autoDerivePorts!: boolean;

  @plugins.smartdata.svDb()
  public performance?: IRemoteIngressPerformanceConfig;

  @plugins.smartdata.svDb()
  public tags!: string[];

  @plugins.smartdata.svDb()
  public createdAt!: number;

  @plugins.smartdata.svDb()
  public updatedAt!: number;

  constructor() {
    super();
  }

  public static async findById(id: string): Promise<RemoteIngressEdgeDoc | null> {
    return await RemoteIngressEdgeDoc.getInstance({ id });
  }

  public static async findAll(): Promise<RemoteIngressEdgeDoc[]> {
    return await RemoteIngressEdgeDoc.getInstances({});
  }

  public static async findEnabled(): Promise<RemoteIngressEdgeDoc[]> {
    return await RemoteIngressEdgeDoc.getInstances({ enabled: true });
  }
}
