import { User } from "api";
import { USER_ROLES } from "components/auth/constants";
import { LICENSE_STATUS } from "./constants";

// 画面表示用のUserの型を独自に定義
export interface UserView
  extends Omit<
    User,
    "typistGroupName" | "prompt" | "encryption" | "remaining"
  > {
  authorId: string;
  typistGroupName: string[] | string;
  role: string;
  licenseStatus: LicenseStatusType | string;
  prompt: boolean | string;
  encryption: boolean | string;
  emailVerified: boolean;
  autoRenew: boolean;
  licenseAlert: boolean;
  notification: boolean;
  name: string;
  email: string;
  expiration: string;
  remaining: number | string;
}

export type RoleType = typeof USER_ROLES[keyof typeof USER_ROLES];

// 受け取った値がUSER_ROLESの型であるかどうかを判定する
export const isRoleType = (role: string): role is RoleType =>
  Object.values(USER_ROLES).includes(role as RoleType);

export type LicenseStatusType =
  typeof LICENSE_STATUS[keyof typeof LICENSE_STATUS];

// 受け取った値がLicenseStatusTypeの型であるかどうかを判定する
export const isLicenseStatusType = (
  licenseStatus: string
): licenseStatus is LicenseStatusType =>
  Object.values(LICENSE_STATUS).includes(licenseStatus as LicenseStatusType);
