import { type Methods, methods } from '../methods' import type { VotingSystem } from '../types' type MethodsContaining< StaticProp extends 'isRandom' | 'needsBallot' | 'needsMatrix', Method, > = Method extends Methods ? Method[StaticProp] extends true ? Method : never : never type SystemsBeing< MethodType extends Methods, System, > = System extends VotingSystem ? (typeof methods)[System] extends MethodType ? System : never : never export type RandomMethods = MethodsContaining<'isRandom', Methods> export type BallotMethods = MethodsContaining<'needsBallot', Methods> export type MatrixMethods = MethodsContaining<'needsMatrix', Methods> export type RandomSystem = SystemsBeing export type BallotSystem = SystemsBeing export type MatrixSystem = SystemsBeing export const isRandomMethod = (Method: Methods): Method is RandomMethods => Method.isRandom export const isBallotMethod = (Method: Methods): Method is BallotMethods => Method.needsBallot export const isMatrixMethod = (Method: Methods): Method is MatrixMethods => Method.needsMatrix export const isRandomSystem = (system: VotingSystem): system is RandomSystem => isRandomMethod(methods[system]) export const isBallotSystem = (system: VotingSystem): system is BallotSystem => isBallotMethod(methods[system]) export const isMatrixSystem = (system: VotingSystem): system is MatrixSystem => isMatrixMethod(methods[system])