/**
 * DevExtreme (esm/ui/scheduler/appointments/DataProvider/appointmentDataProvider.js)
 * Version: 21.2.0 (build 21200-0321)
 * Build date: Mon Jul 19 2021
 *
 * Copyright (c) 2012 - 2021 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import {
    AppointmentDataSource
} from "./appointmentDataSource";
import {
    AppointmentFilterBaseStrategy,
    AppointmentFilterVirtualStrategy
} from "./appointmentFilter";
var FilterStrategies = {
    virtual: "virtual",
    standard: "standard"
};
export class AppointmentDataProvider {
    constructor(options) {
        this.options = options;
        this.key = this.options.key;
        this.scheduler = this.options.scheduler;
        this.dataSource = this.options.dataSource;
        this.dataAccessors = this.options.getDataAccessors(this.key);
        this.filteredItems = [];
        this.appointmentDataSource = new AppointmentDataSource(this.dataSource);
        this.initFilterStrategy()
    }
    get filterMaker() {
        return this.getFilterStrategy().filterMaker
    }
    get keyName() {
        return this.appointmentDataSource.keyName
    }
    get filterStrategyName() {
        return this.options.getIsVirtualScrolling() ? FilterStrategies.virtual : FilterStrategies.standard
    }
    getDataAccessors() {
        return this.dataAccessors
    }
    getFilterStrategy() {
        if (!this.filterStrategy || this.filterStrategy.strategyName !== this.filterStrategyName) {
            this.initFilterStrategy()
        }
        return this.filterStrategy
    }
    initFilterStrategy() {
        var filterOptions = {
            key: this.key,
            scheduler: this.scheduler,
            dataSource: this.dataSource,
            dataAccessors: this.dataAccessors,
            startDayHour: this.options.startDayHour,
            endDayHour: this.options.endDayHour,
            appointmentDuration: this.options.appointmentDuration,
            showAllDayPanel: this.options.showAllDayPanel,
            timeZoneCalculator: this.options.timeZoneCalculator,
            resourceManager: this.options.resourceManager
        };
        this.filterStrategy = this.filterStrategyName === FilterStrategies.virtual ? new AppointmentFilterVirtualStrategy(filterOptions) : new AppointmentFilterBaseStrategy(filterOptions)
    }
    setDataSource(dataSource) {
        this.dataSource = dataSource;
        this.initFilterStrategy();
        this.appointmentDataSource.setDataSource(this.dataSource)
    }
    updateDataAccessors(dataAccessors) {
        this.dataAccessors = dataAccessors;
        this.initFilterStrategy()
    }
    filter() {
        this.filteredItems = this.getFilterStrategy().filter()
    }
    filterByDate(min, max, remoteFiltering, dateSerializationFormat) {
        this.getFilterStrategy().filterByDate(min, max, remoteFiltering, dateSerializationFormat)
    }
    appointmentTakesAllDay(appointment, startDayHour, endDayHour) {
        return this.getFilterStrategy().appointmentTakesAllDay(appointment, startDayHour, endDayHour)
    }
    hasAllDayAppointments(appointments) {
        return this.getFilterStrategy().hasAllDayAppointments(appointments)
    }
    filterLoadedAppointments(filterOption, timeZoneCalculator) {
        return this.getFilterStrategy().filterLoadedAppointments(filterOption, timeZoneCalculator)
    }
    replaceWrongEndDate(appointment, startDate, endDate) {
        this.getFilterStrategy().replaceWrongEndDate(appointment, startDate, endDate)
    }
    calculateAppointmentEndDate(isAllDay, startDate) {
        return this.getFilterStrategy().calculateAppointmentEndDate(isAllDay, startDate)
    }
    appointmentTakesSeveralDays(appointment) {
        return this.getFilterStrategy().appointmentTakesSeveralDays(appointment)
    }
    cleanState() {
        this.appointmentDataSource.cleanState()
    }
    getUpdatedAppointment() {
        return this.appointmentDataSource._updatedAppointment
    }
    getUpdatedAppointmentKeys() {
        return this.appointmentDataSource._updatedAppointmentKeys
    }
    add(rawAppointment) {
        return this.appointmentDataSource.add(rawAppointment)
    }
    update(target, rawAppointment) {
        return this.appointmentDataSource.update(target, rawAppointment)
    }
    remove(rawAppointment) {
        return this.appointmentDataSource.remove(rawAppointment)
    }
}
