/*
 * Copyright (C) 2021 StApps
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

import {
  StorageBackend,
  Requestor,
  AuthorizationServiceConfiguration,
} from '@openid/appauth';
import {Browser} from 'ionic-appauth';
import {environment} from 'src/environments/environment';
import {DefaultAuthService} from '../default-auth.service';
import {PAIAAuthService} from '../paia/paia-auth.service';

export const authFactory = (
  requestor: Requestor,
  browser: Browser,
  storage: StorageBackend,
) => {
  const authService = new DefaultAuthService(browser, storage, requestor);
  authService.authConfig = environment.oauth2.client.his;
  authService.localConfiguration = new AuthorizationServiceConfiguration(
    environment.oauth2.service.his,
  );

  return authService;
};

export const paiaAuthFactory = (
  requestor: Requestor,
  browser: Browser,
  storage: StorageBackend,
) => {
  const authService = new PAIAAuthService(browser, storage, requestor);
  authService.authConfig = environment.oauth2.client.paia;
  authService.localConfiguration = new AuthorizationServiceConfiguration(
    environment.oauth2.service.paia,
  );

  return authService;
};
