import { Inspection , InspectionAmPmRange , InspectionDayKindRange , InspectionDayOfMonthRange , InspectionDayOfWeekRange , InspectionHalfMonthRange , InspectionHalfWeekRange , InspectionHalfYearRange , InspectionHourKindRange , InspectionHourRange , InspectionMonthRange , InspectionQuarterRange , InspectionTenDaysRange , InspectionTimeRange , InspectionWeekOfMonthRange , InspectionWeekOfYearRange , InspectionYearRange } from '@/services/data/tuples/inspection-types' ; import { isInspectionAmPmRange , isInspectionDayKindRange , isInspectionDayOfMonthRange , isInspectionDayOfWeekRange , isInspectionHalfMonthRange , isInspectionHalfWeekRange , isInspectionHalfYearRange , isInspectionHourKindRange , isInspectionHourRange , isInspectionMonthRange , isInspectionQuarterRange , isInspectionTenDaysRange , isInspectionWeekOfMonthRange , isInspectionWeekOfYearRange , isInspectionYearRange } from '@/services/data/tuples/inspection-utils' ; import { isNotNull } from '@/services/data/utils' ; export const getValidRanges = ( inspection ? ) : Array < InspectionTimeRange > => { if ( inspection == null ) { return [ ] ; } if ( inspection . timeRanges == null || inspection . timeRanges . length === 0 ) { return [ ] ; } return inspection . timeRanges . filter ( isNotNull ) ; } ; const acceptAll = < R extends InspectionTimeRange > ( range ) : range is R => true ; export const getValidRangesByType = < R extends InspectionTimeRange > ( inspection ? , accept = acceptAll ) : Array < R > => { return getValidRanges ( inspection ) . filter ( accept ) . filter ( range => range . value != null ) ; } ; export const getValidYearRanges = ( inspection ? ) : Array < InspectionYearRange > => getValidRangesByType ( inspection , isInspectionYearRange ) ; export const getValidHalfYearRanges = ( inspection ? ) : Array < InspectionHalfYearRange > => getValidRangesByType ( inspection , isInspectionHalfYearRange ) ; export const getValidQuarterRanges = ( inspection ? ) : Array < InspectionQuarterRange > => getValidRangesByType ( inspection , isInspectionQuarterRange ) ; export const getValidMonthRanges = ( inspection ? ) : Array < InspectionMonthRange > => getValidRangesByType ( inspection , isInspectionMonthRange ) ; export const getValidHalfMonthRanges = ( inspection ? ) : Array < InspectionHalfMonthRange > => getValidRangesByType ( inspection , isInspectionHalfMonthRange ) ; export const getValidTenDaysRanges = ( inspection ? ) : Array < InspectionTenDaysRange > => getValidRangesByType ( inspection , isInspectionTenDaysRange ) ; export const getValidWeekOfYearRanges = ( inspection ? ) : Array < InspectionWeekOfYearRange > => getValidRangesByType ( inspection , isInspectionWeekOfYearRange ) ; export const getValidWeekOfMonthRanges = ( inspection ? ) : Array < InspectionWeekOfMonthRange > => getValidRangesByType ( inspection , isInspectionWeekOfMonthRange ) ; export const getValidHalfWeekRanges = ( inspection ? ) : Array < InspectionHalfWeekRange > => getValidRangesByType ( inspection , isInspectionHalfWeekRange ) ; export const getValidDayOfMonthRanges = ( inspection ? ) : Array < InspectionDayOfMonthRange > => getValidRangesByType ( inspection , isInspectionDayOfMonthRange ) ; export const getValidDayOfWeekRanges = ( inspection ? ) : Array < InspectionDayOfWeekRange > => getValidRangesByType ( inspection , isInspectionDayOfWeekRange ) ; export const getValidDayKindRanges = ( inspection ? ) : Array < InspectionDayKindRange > => getValidRangesByType ( inspection , isInspectionDayKindRange ) ; export const getValidHourRanges = ( inspection ? ) : Array < InspectionHourRange > => getValidRangesByType ( inspection , isInspectionHourRange ) ; export const getValidHourKindRanges = ( inspection ? ) : Array < InspectionHourKindRange > => getValidRangesByType ( inspection , isInspectionHourKindRange ) ; export const getValidAmPmRanges = ( inspection ? ) : Array < InspectionAmPmRange > => getValidRangesByType ( inspection , isInspectionAmPmRange ) ;