package com.cloudhandson.vpdbackoffice.domain.token;

import java.time.LocalDateTime;
import java.util.List;

public record TokenContextView(
    long keyId,
    long userId,
    String username,
    String stakeholderUserId,
    String stakeholderRole,
    String stakeholderChannel,
    String keyPrefix,
    LocalDateTime expiresAt,
    LocalDateTime revokedAt,
    String description,
    boolean active,
    List<String> directRoles,
    List<String> groups,
    List<String> inheritedRoles
) {

  public String statusLabel() {
    if (active) {
      return "ACTIVE";
    }
    return revokedAt == null ? "EXPIRED" : "REVOKED";
  }

  public String maskedToken() {
    if (keyPrefix == null || keyPrefix.isBlank()) {
      return "****";
    }
    return keyPrefix + "****";
  }

  public String displayLabel() {
    return "#" + keyId + " / " + username + " / " + statusLabel();
  }
}
