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

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

@plugins.smartdata.Collection(() => getDb())
export class TargetProfileDoc extends plugins.smartdata.SmartDataDbDoc<TargetProfileDoc, TargetProfileDoc> {
  @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 domains?: string[];

  @plugins.smartdata.svDb()
  public targets?: ITargetProfileTarget[];

  @plugins.smartdata.svDb()
  public routeRefs?: string[];

  @plugins.smartdata.svDb()
  public allowRoutesByClientSourceIp?: boolean;

  @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<TargetProfileDoc | null> {
    return await TargetProfileDoc.getInstance({ id });
  }

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