import { AwsS3Integration } from './awsS3/AwsS3Integration.esm.js';
import { AwsCodeCommitIntegration } from './awsCodeCommit/AwsCodeCommitIntegration.esm.js';
import { AzureIntegration } from './azure/AzureIntegration.esm.js';
import { BitbucketCloudIntegration } from './bitbucketCloud/BitbucketCloudIntegration.esm.js';
import { BitbucketIntegration } from './bitbucket/BitbucketIntegration.esm.js';
import { BitbucketServerIntegration } from './bitbucketServer/BitbucketServerIntegration.esm.js';
import { GerritIntegration } from './gerrit/GerritIntegration.esm.js';
import { GithubIntegration } from './github/GithubIntegration.esm.js';
import { GitLabIntegration } from './gitlab/GitLabIntegration.esm.js';
import { defaultScmResolveUrl } from './helpers.esm.js';
import { GiteaIntegration } from './gitea/GiteaIntegration.esm.js';
import 'lodash';
import { HarnessIntegration } from './harness/HarnessIntegration.esm.js';
import { AzureBlobStorageIntergation } from './azureBlobStorage/AzureBlobStorageIntegration.esm.js';
import '@azure/identity';

class ScmIntegrations {
  byType;
  static fromConfig(config) {
    return new ScmIntegrations({
      awsS3: AwsS3Integration.factory({ config }),
      awsCodeCommit: AwsCodeCommitIntegration.factory({ config }),
      azureBlobStorage: AzureBlobStorageIntergation.factory({ config }),
      azure: AzureIntegration.factory({ config }),
      bitbucket: BitbucketIntegration.factory({ config }),
      bitbucketCloud: BitbucketCloudIntegration.factory({ config }),
      bitbucketServer: BitbucketServerIntegration.factory({ config }),
      gerrit: GerritIntegration.factory({ config }),
      github: GithubIntegration.factory({ config }),
      gitlab: GitLabIntegration.factory({ config }),
      gitea: GiteaIntegration.factory({ config }),
      harness: HarnessIntegration.factory({ config })
    });
  }
  constructor(integrationsByType) {
    this.byType = integrationsByType;
  }
  get awsS3() {
    return this.byType.awsS3;
  }
  get awsCodeCommit() {
    return this.byType.awsCodeCommit;
  }
  get azureBlobStorage() {
    return this.byType.azureBlobStorage;
  }
  get azure() {
    return this.byType.azure;
  }
  /**
   * @deprecated in favor of `bitbucketCloud()` and `bitbucketServer()`
   */
  get bitbucket() {
    return this.byType.bitbucket;
  }
  get bitbucketCloud() {
    return this.byType.bitbucketCloud;
  }
  get bitbucketServer() {
    return this.byType.bitbucketServer;
  }
  get gerrit() {
    return this.byType.gerrit;
  }
  get github() {
    return this.byType.github;
  }
  get gitlab() {
    return this.byType.gitlab;
  }
  get gitea() {
    return this.byType.gitea;
  }
  get harness() {
    return this.byType.harness;
  }
  list() {
    return Object.values(this.byType).flatMap(
      (i) => i.list()
    );
  }
  byUrl(url) {
    let candidates = Object.values(this.byType).map((i) => i.byUrl(url)).filter(Boolean);
    if (candidates.length > 1) {
      const filteredCandidates = candidates.filter(
        (x) => !(x instanceof BitbucketIntegration)
      );
      if (filteredCandidates.length !== 0) {
        candidates = filteredCandidates;
      }
    }
    return candidates[0];
  }
  byHost(host) {
    return Object.values(this.byType).map((i) => i.byHost(host)).find(Boolean);
  }
  resolveUrl(options) {
    const integration = this.byUrl(options.base);
    if (!integration) {
      return defaultScmResolveUrl(options);
    }
    return integration.resolveUrl(options);
  }
  resolveEditUrl(url) {
    const integration = this.byUrl(url);
    if (!integration) {
      return url;
    }
    return integration.resolveEditUrl(url);
  }
}

export { ScmIntegrations };
//# sourceMappingURL=ScmIntegrations.esm.js.map
