import { DeviceLocation } from '../value-objects/device-location';
import { DeviceStatus } from '../value-objects/device-status';

export class Device {
  constructor(
    public readonly id: string,
    public readonly location: DeviceLocation,
    public readonly type: string,
    public readonly info: string | null,
    public readonly ipAddress: string,
    public readonly userAgent: string | null,
    public readonly fingerprint: string,
    public readonly status: DeviceStatus,
    public readonly pushToken: string | null,
    public readonly createdAt: Date,
    public readonly updatedAt: Date,
  ) {}

  public static create(
    id: string,
    location: DeviceLocation,
    type: string,
    info: string | null,
    ipAddress: string,
    userAgent: string | null,
    fingerprint: string,
    status: DeviceStatus = 'closed',
    pushToken: string | null = null,
  ): Device {
    const now = new Date();
    return new Device(
      id,
      location,
      type,
      info,
      ipAddress,
      userAgent,
      fingerprint,
      status,
      pushToken,
      now,
      now,
    );
  }

  public updateStatus(status: DeviceStatus): Device {
    return new Device(
      this.id,
      this.location,
      this.type,
      this.info,
      this.ipAddress,
      this.userAgent,
      this.fingerprint,
      status,
      this.pushToken,
      this.createdAt,
      new Date(),
    );
  }

  public updatePushToken(pushToken: string | null): Device {
    return new Device(
      this.id,
      this.location,
      this.type,
      this.info,
      this.ipAddress,
      this.userAgent,
      this.fingerprint,
      this.status,
      pushToken,
      this.createdAt,
      new Date(),
    );
  }
}
