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

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

/**
 * Singleton ACME configuration document. One row per dcrouter instance,
 * keyed on the fixed `configId = 'acme-config'` following the
 * `VpnServerKeysDoc` pattern.
 *
 * Managed via the OpsServer UI at **Domains > Certificates > Settings**.
 */
@plugins.smartdata.Collection(() => getDb())
export class AcmeConfigDoc extends plugins.smartdata.SmartDataDbDoc<AcmeConfigDoc, AcmeConfigDoc> {
  @plugins.smartdata.unI()
  @plugins.smartdata.svDb()
  public configId: string = 'acme-config';

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

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

  @plugins.smartdata.svDb()
  public useProduction: boolean = true;

  @plugins.smartdata.svDb()
  public autoRenew: boolean = true;

  @plugins.smartdata.svDb()
  public renewThresholdDays: number = 30;

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

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

  constructor() {
    super();
  }

  public static async load(): Promise<AcmeConfigDoc | null> {
    return await AcmeConfigDoc.getInstance({ configId: 'acme-config' });
  }
}
