// トークンの型やtypeGuardの関数を配置するファイル
export interface Token {
  userId: string;
  role: string;
  tier: number;
  exp: number;
  iat: number;
}

// Type Guard
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const isToken = (arg: any): arg is Token => {
  if (arg.userId === undefined) {
    return false;
  }
  if (arg.role === undefined) {
    return false;
  }
  if (arg.tier === undefined) {
    return false;
  }
  if (arg.exp === undefined) {
    return false;
  }
  if (arg.iat === undefined) {
    return false;
  }

  return true;
};

interface IdToken {
  credentialType: string;
  homeAccountId: string;
  environment: string;
  clientId: string;
  secret: string;
  realm: string;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const isIdToken = (arg: any): arg is IdToken => {
  const idToken = arg as IdToken;
  if (idToken.credentialType === undefined) {
    return false;
  }
  if (idToken.homeAccountId === undefined) {
    return false;
  }
  if (idToken.environment === undefined) {
    return false;
  }
  if (idToken.clientId === undefined) {
    return false;
  }
  if (idToken.secret === undefined) {
    return false;
  }
  if (idToken.realm === undefined) {
    return false;
  }

  return true;
};
