import { SyncType } from '../value-objects/sync-type';

export class Wallet {
  constructor(
    public readonly id: string,
    public readonly name: string,
    public readonly syncType: SyncType,
    public readonly syncedAt: Date,
    public readonly encryptedPhrase: string,
    public readonly deviceIds: string[],
    public readonly isAdmin: boolean,
    public readonly isActive: boolean,
    public readonly lastAccessedAt: Date,
    public readonly version: number,
    public readonly createdAt: Date,
    public readonly updatedAt: Date,
  ) {}

  public static create(
    id: string,
    name: string,
    syncType: SyncType,
    encryptedPhrase: string,
    deviceIds: string[],
    isAdmin = false,
  ): Wallet {
    const now = new Date();
    return new Wallet(
      id,
      name,
      syncType,
      now,
      encryptedPhrase,
      deviceIds,
      isAdmin,
      true,
      now,
      1,
      now,
      now,
    );
  }

  public withEncryptedPhrase(encryptedPhrase: string): Wallet {
    return new Wallet(
      this.id,
      this.name,
      this.syncType,
      this.syncedAt,
      encryptedPhrase,
      this.deviceIds,
      this.isAdmin,
      this.isActive,
      new Date(),
      this.version,
      this.createdAt,
      new Date(),
    );
  }

  public touch(): Wallet {
    return new Wallet(
      this.id,
      this.name,
      this.syncType,
      this.syncedAt,
      this.encryptedPhrase,
      this.deviceIds,
      this.isAdmin,
      this.isActive,
      new Date(),
      this.version,
      this.createdAt,
      new Date(),
    );
  }

  public incrementVersion(): Wallet {
    return new Wallet(
      this.id,
      this.name,
      this.syncType,
      this.syncedAt,
      this.encryptedPhrase,
      this.deviceIds,
      this.isAdmin,
      this.isActive,
      new Date(),
      this.version + 1,
      this.createdAt,
      new Date(),
    );
  }
}
