import type { IUnifiedEmailServerOptions } from '@push.rocks/smartmta';
import * as plugins from '../../plugins.js';
import { DcRouterDb } from '../classes.dcrouter-db.js';
import type { IEmailPortConfig } from '../../../ts_interfaces/data/email-settings.js';

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

@plugins.smartdata.Collection(() => getDb())
export class EmailServerSettingsDoc extends plugins.smartdata.SmartDataDbDoc<EmailServerSettingsDoc, EmailServerSettingsDoc> {
  @plugins.smartdata.unI()
  @plugins.smartdata.svDb()
  public settingsId: string = 'email-server-settings';

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

  @plugins.smartdata.svDb()
  public emailConfig?: IUnifiedEmailServerOptions;

  @plugins.smartdata.svDb()
  public emailPortConfig?: IEmailPortConfig;

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

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

  constructor() {
    super();
  }

  public static async load(): Promise<EmailServerSettingsDoc | null> {
    return await EmailServerSettingsDoc.getInstance({ settingsId: 'email-server-settings' });
  }

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