import * as i0 from '@angular/core';
import { Injectable } from '@angular/core';
import * as i1 from '@c8y/ngx-components';
import { agentName } from '@c8y/ngx-components/protocol-lwm2m/model';
import * as i1$1 from '@c8y/ngx-components/protocol-lwm2m/services';
import { of } from 'rxjs';
import { switchMap, catchError, map } from 'rxjs/operators';

class Lwm2mMicroserviceGuard {
    constructor(tenantService) {
        this.tenantService = tenantService;
    }
    canActivate() {
        return this.tenantService.isMicroserviceSubscribedInCurrentTenant(agentName);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mMicroserviceGuard, deps: [{ token: i1.TenantUiService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mMicroserviceGuard, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mMicroserviceGuard, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i1.TenantUiService }] });

class Lwm2mDeviceTypeGuard {
    constructor(lwm2mClientService) {
        this.lwm2mClientService = lwm2mClientService;
    }
    canActivate(route) {
        return this.lwm2mClientService.isLwm2mDevice(route?.data?.contextData || route?.parent?.data?.contextData);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mDeviceTypeGuard, deps: [{ token: i1$1.Lwm2mClientService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mDeviceTypeGuard, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mDeviceTypeGuard, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i1$1.Lwm2mClientService }] });

class Lwm2mConfigurationApiGuard {
    constructor(lwm2mConfigService) {
        this.lwm2mConfigService = lwm2mConfigService;
        this.NOT_FOUND = 404;
    }
    canActivate() {
        return this.lwm2mConfigService.fetchServerCertificates$().pipe(switchMap(_data => of(true)), catchError(err => {
            return err?.res?.status === this.NOT_FOUND ? of(false) : of(true);
        }));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mConfigurationApiGuard, deps: [{ token: i1$1.Lwm2mConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mConfigurationApiGuard, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mConfigurationApiGuard, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i1$1.Lwm2mConfigurationService }] });

class Lwm2mBootstrapParametersApiGuard extends Lwm2mConfigurationApiGuard {
    constructor(lwm2mConfigService) {
        super(lwm2mConfigService);
        this.lwm2mConfigService = lwm2mConfigService;
    }
    canActivate() {
        return super.canActivate().pipe(map(data => !data));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mBootstrapParametersApiGuard, deps: [{ token: i1$1.Lwm2mConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mBootstrapParametersApiGuard, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: Lwm2mBootstrapParametersApiGuard, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i1$1.Lwm2mConfigurationService }] });

/**
 * Generated bundle index. Do not edit.
 */

export { Lwm2mBootstrapParametersApiGuard, Lwm2mConfigurationApiGuard, Lwm2mDeviceTypeGuard, Lwm2mMicroserviceGuard };
//# sourceMappingURL=c8y-ngx-components-protocol-lwm2m-guards.mjs.map
