import type { AccessRule } from '@api-client/core/modeling/types.js'
import type { ApiModelAccessTarget, ApiModelOperationName } from '../types.js'

/**
 * Check if the given value is a valid operation name.
 */
export function isValidOperationName(value = ''): value is ApiModelOperationName {
  return ['list', 'read', 'create', 'update', 'delete', 'search'].includes(value)
}

/**
 * Check if the given value is a valid access target.
 */
export function isValidAccessTarget(value = ''): value is ApiModelAccessTarget {
  return ['api', 'action', 'endpoint'].includes(value)
}

/**
 * Check if the given value is a valid access rule type.
 */
export function isValidAccessRuleType(value = ''): value is AccessRule['type'] {
  return [
    'public',
    'authenticated',
    'resourceOwner',
    'matchUserRole',
    'matchUserProperty',
    'matchEmailDomain',
  ].includes(value)
}
