package com.cloudhandson.vpdbackoffice.domain.protectedobject;

import java.util.Locale;

public record ProtectedColumn(
    long columnId,
    long objectId,
    String columnName,
    String sensitiveYn,
    Long visibleRoleId,
    String sensitivityLevel,
    String redactionMethod
) {

  public boolean sensitive() {
    return "Y".equalsIgnoreCase(sensitiveYn)
        || !"PUBLIC".equalsIgnoreCase(sensitivityLevel);
  }

  public String policyLabel() {
    String level = sensitivityLevel == null || sensitivityLevel.isBlank() ? "PUBLIC" : sensitivityLevel;
    String method = redactionMethod == null || redactionMethod.isBlank() ? "NONE" : redactionMethod;
    return level + "/" + method;
  }

  public String sensitivityLabel() {
    String level = sensitivityLevel == null || sensitivityLevel.isBlank() ? "PUBLIC" : sensitivityLevel;
    return switch (level.toUpperCase(Locale.ROOT)) {
      case "INTERNAL" -> "내부용";
      case "CONFIDENTIAL" -> "기밀";
      case "RESTRICTED" -> "제한";
      default -> "기본 표시";
    };
  }

  public String redactionLabel() {
    String method = redactionMethod == null || redactionMethod.isBlank() ? "NONE" : redactionMethod;
    return switch (method.toUpperCase(Locale.ROOT)) {
      case "NULLIFY" -> "값 숨김(NULL)";
      case "PARTIAL" -> "일부 숨김";
      case "FULL" -> "전체 숨김";
      default -> "마스킹 없음";
    };
  }

  public String displayPolicyLabel() {
    return sensitive() ? sensitivityLabel() + " · " + redactionLabel() : "기본 표시 · 마스킹 없음";
  }
}
