import * as plugins from '../../plugins.js';
import { DcRouterDb } from '../classes.dcrouter-db.js';

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

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

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

  @plugins.smartdata.svDb()
  public description?: string;

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

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

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

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

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

  constructor() {
    super();
  }

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

  public static async findByName(name: string): Promise<NetworkTargetDoc | null> {
    return await NetworkTargetDoc.getInstance({ name });
  }

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