package com.airlock.iam.common.domain.model.device.usage;

import com.airlock.iam.base.api.domain.model.user.UserId;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.time.Instant;

public final class DeviceUsage {
   private final UserId userId;
   private final String deviceType;
   private final String deviceId;
   private final int totalUsages;
   private final Instant firstUsedAt;
   private final Instant lastUsedAt;

   public static DeviceUsage firstDeviceUsage(UserId userId, String deviceType, String deviceId, Instant usedAt) {
      return new DeviceUsage(userId, deviceType, deviceId, 1, usedAt, usedAt);
   }

   public DeviceUsage withNewUsage(Instant usedAt) {
      return new DeviceUsage(this.userId, this.deviceType, this.deviceId, this.totalUsages + 1, this.firstUsedAt, usedAt);
   }

   @SuppressFBWarnings(justification = "generated code")
   public DeviceUsage(UserId userId, String deviceType, String deviceId, int totalUsages, Instant firstUsedAt, Instant lastUsedAt) {
      this.userId = userId;
      this.deviceType = deviceType;
      this.deviceId = deviceId;
      this.totalUsages = totalUsages;
      this.firstUsedAt = firstUsedAt;
      this.lastUsedAt = lastUsedAt;
   }

   @SuppressFBWarnings(justification = "generated code")
   public UserId userId() {
      return this.userId;
   }

   @SuppressFBWarnings(justification = "generated code")
   public String deviceType() {
      return this.deviceType;
   }

   @SuppressFBWarnings(justification = "generated code")
   public String deviceId() {
      return this.deviceId;
   }

   @SuppressFBWarnings(justification = "generated code")
   public int totalUsages() {
      return this.totalUsages;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Instant firstUsedAt() {
      return this.firstUsedAt;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Instant lastUsedAt() {
      return this.lastUsedAt;
   }
}
