tazakazahstan/src/points/rates.ts
2026-11-14 15:37:13 +05:00

28 lines
986 B
TypeScript

export const CONTAINER_TYPES = ["pet", "aluminum", "glass"] as const;
export type ContainerType = (typeof CONTAINER_TYPES)[number];
export interface ContainerItem {
type: ContainerType;
volumeMl: number;
count: number;
}
/** Порог «малой» тары (включительно). */
const SMALL_MAX_ML = 500;
/** Баллы за единицу тары: [до 500 мл включительно, больше 500 мл]. Предложение для пилота. */
export const POINT_RATES: Record<ContainerType, readonly [small: number, large: number]> = {
pet: [1, 2],
aluminum: [2, 2],
glass: [2, 3],
};
export function pointsPerUnit(type: ContainerType, volumeMl: number): number {
const [small, large] = POINT_RATES[type];
return volumeMl <= SMALL_MAX_ML ? small : large;
}
export function pointsForItems(items: readonly ContainerItem[]): number {
return items.reduce((sum, item) => sum + pointsPerUnit(item.type, item.volumeMl) * item.count, 0);
}