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

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

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

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

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

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

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

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

  constructor() {
    super();
  }

  public static async findByDomain(domain: string): Promise<ProxyCertDoc | null> {
    return await ProxyCertDoc.getInstance({ domain });
  }

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