import { AccountDTO } from './account.dto';
import { AccountVisitor } from './visitor.interface';

export class Account {
  private _dto: AccountDTO;
  private _decryptedData: Record<string, string | undefined>; // Could be typed further (e.g., { login, password, notes, url })

  constructor(dto: AccountDTO, decryptedData?: Record<string, string | undefined>) {
    this._dto = dto;
    this._decryptedData = decryptedData || {};
  }

  get id(): string {
    return this._dto.id;
  }

  get serviceName(): string {
    return this._dto.service_name;
  }

  get updatedAt(): Date {
    return new Date(this._dto.updated_at);
  }

  get isDeleted(): boolean {
    return this._dto.is_deleted;
  }

  get decryptedData(): Record<string, string | undefined> {
    return this._decryptedData;
  }

  set decryptedData(data: Record<string, string | undefined>) {
    this._decryptedData = data;
  }

  /**
   * Validates if the account currently has required fields decrypted (e.g., login, password).
   */
  isValid(): boolean {
    return !!this._decryptedData?.['login'] && !!this._decryptedData?.['password'];
  }

  /**
   * Implements the Visitor pattern for operations like export.
   */
  accept(visitor: AccountVisitor): void {
    visitor.visitAccount(this);
  }
}
