import Stop from '../../Stop/entity/Stop'; import TravelStopType from '../enums/TravelStopType'; import ValidableInterface from '../../common/interfaces/ValidableInterface'; import BaseEntity from '../../common/entities/BaseEntity'; import TravelStopPricing from '../../TravelStopPricing/entity/TravelStopPricing'; export default abstract class TravelStop extends BaseEntity implements ValidableInterface { private _stop: Stop = null; private _type: TravelStopType; private _pricings: Array = []; private _stop_order: number; private _time_to_reach: number; private _distance: number; private _unallocated: any; private _not_travelling: any; get stop(): Stop { return this._stop; } set stop(value: Stop) { this._stop = value; } get type(): TravelStopType { return this._type; } set type(value: TravelStopType) { this._type = value; } get pricings(): Array { return this._pricings; } set pricings(value: Array) { this._pricings = value; } get stop_order(): number { return this._stop_order; } set stop_order(value: number) { this._stop_order = value; } get time_to_reach(): number { return this._time_to_reach; } set time_to_reach(value: number) { this._time_to_reach = value; } get distance(): number { return this._distance; } set distance(value: number) { this._distance = value; } get unallocated(): any { return this._unallocated; } set unallocated(value: any) { this._unallocated = value; } get not_travelling(): any { return this._not_travelling; } set not_travelling(value: any) { this._not_travelling = value; } addPricing(item: TravelStopPricing) { this.pricings.push(item); } removePricing(item: TravelStopPricing) { let index = this.pricings.findIndex((each: TravelStopPricing) => each.id === item.id); index !== -1 && this.pricings.slice(index, 1); } resetPricing() { this.pricings = []; } isPickup() { return this.type === TravelStopType.TYPE_PICKUP || this.type === TravelStopType.TYPE_BOTH; } isDropoff() { return this.type === TravelStopType.TYPE_DROPOFF || this.type === TravelStopType.TYPE_BOTH; } isPickupAndDropoff() { return this.type === TravelStopType.TYPE_BOTH; } public isValid() { return this.invalidFields().length === 0; } public invalidFields() { let fields = []; !this._stop && fields.push('stop'); return fields; } }