import { Check, Column } from 'typeorm';

export const minValue = 0;
export const maxValue = Number.MAX_SAFE_INTEGER;

export interface IRateable {
  rating: number;
}

export function Rateable<T extends Constructor>(BaseClass: T = null): T {
  @Check(`rating >= ${minValue} AND rating <= ${maxValue}`)
  class MixinClass extends BaseClass implements IRateable {
    @Column({ nullable: true })
    public rating: number;
  }

  return MixinClass;
}
