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

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

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

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

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

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

  constructor() {
    super();
  }

  public static async findByRouteName(routeName: string): Promise<RouteOverrideDoc | null> {
    return await RouteOverrideDoc.getInstance({ routeName });
  }

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