import { CommitFilesConfig, LongCommitSha } from "../../util/git/types.js";
import { GithubVulnerabilityAlert } from "./github/schema.js";
import { BranchStatus } from "../../types/branch-status.js";
import { HostRule } from "../../types/host-rules.js";
import { MergeStrategy } from "../../config/types.js";
import { DateTime } from "luxon";

//#region lib/modules/platform/types.d.ts
type VulnerabilityAlert = GithubVulnerabilityAlert;
interface PlatformParams {
  dryRun?: string;
  endpoint?: string;
  token?: string;
  username?: string;
  password?: string;
  gitAuthor?: string;
}
interface PlatformResult {
  endpoint: string;
  renovateUsername?: string;
  token?: string;
  gitAuthor?: string;
  hostRules?: HostRule[];
}
interface RepoResult {
  defaultBranch: string;
  isFork: boolean;
  repoFingerprint: string;
}
type GitUrlOption = 'default' | 'ssh' | 'endpoint';
interface RepoParams {
  repository: string;
  gitUrl?: GitUrlOption;
  forkCreation?: boolean;
  forkOrg?: string;
  forkToken?: string;
  forkProcessing?: 'enabled' | 'disabled';
  renovateUsername?: string;
  cloneSubmodules?: boolean;
  cloneSubmodulesFilter?: string[];
}
interface PrDebugData {
  createdInVer: string;
  updatedInVer: string;
  targetBranch: string;
  labels?: string[];
}
interface PrBodyStruct {
  hash: string;
  rawConfigHash?: string;
  rebaseRequested?: boolean;
  debugData?: PrDebugData;
}
/**
 *
 */
interface Pr {
  bodyStruct?: PrBodyStruct;
  sourceBranch: string;
  cannotMergeReason?: string;
  createdAt?: string;
  closedAt?: string;
  hasAssignees?: boolean;
  labels?: string[];
  number: number;
  reviewers?: string[];
  sha?: LongCommitSha;
  sourceRepo?: string;
  state: string;
  targetBranch?: string;
  title: string;
  isDraft?: boolean;
}
/**
 * TODO: Proper typing
 */
interface Issue {
  body?: string;
  number?: number;
  state?: string;
  title?: string;
  createdAt?: string;
  lastModified?: string;
}
interface PlatformPrOptions {
  autoApprove?: boolean;
  automergeCommitMessage?: string;
  automergeStrategy?: MergeStrategy;
  azureWorkItemId?: number;
  bbUseDefaultReviewers?: boolean;
  bbAutoResolvePrTasks?: boolean;
  gitLabIgnoreApprovals?: boolean;
  usePlatformAutomerge?: boolean;
  forkModeDisallowMaintainerEdits?: boolean;
}
interface CreatePRConfig {
  sourceBranch: string;
  targetBranch: string;
  prTitle: string;
  prBody: string;
  labels?: string[] | null;
  platformPrOptions?: PlatformPrOptions;
  draftPR?: boolean;
  milestone?: number;
}
interface UpdatePrConfig {
  number: number;
  platformPrOptions?: PlatformPrOptions;
  prTitle: string;
  prBody?: string;
  state?: 'open' | 'closed';
  targetBranch?: string;
  /**
   * This field allows for label management and is designed to
   * accommodate the different label update methods on various platforms.
   *
   * - For Gitea, labels are updated by replacing the entire labels array.
   * - In the case of GitHub and GitLab, specific endpoints exist
   *   for adding and removing labels.
   */
  labels?: string[] | null;
  /**
   * Specifies an array of labels to be added.
   * @see {@link labels}
   */
  addLabels?: string[] | null;
  /**
   * Specifies an array of labels to be removed.
   * @see {@link labels}
   */
  removeLabels?: string[] | null;
}
interface ReattemptPlatformAutomergeConfig {
  number: number;
  platformPrOptions?: PlatformPrOptions;
}
interface EnsureIssueConfig {
  title: string;
  reuseTitle?: string;
  body: string;
  labels?: string[];
  once?: boolean;
  shouldReOpen?: boolean;
  confidential?: boolean;
}
interface StatusCheckConfig {
  context: string;
  description: string;
  state: BranchStatus;
  url?: string;
}
interface BranchStatusConfig extends StatusCheckConfig {
  branchName: string;
}
interface FindPRConfig {
  branchName: string;
  prTitle?: string | null;
  state?: 'open' | 'closed' | '!open' | 'all';
  refreshCache?: boolean;
  targetBranch?: string | null;
  includeOtherAuthors?: boolean;
}
interface MergePRConfig {
  branchName?: string;
  id: number;
  strategy?: MergeStrategy;
}
interface EnsureCommentConfig {
  number: number;
  topic: string | null;
  content: string;
}
interface EnsureCommentRemovalConfigByTopic {
  type: 'by-topic';
  number: number;
  topic: string;
}
interface EnsureCommentRemovalConfigByContent {
  type: 'by-content';
  number: number;
  content: string;
}
type EnsureCommentRemovalConfig = EnsureCommentRemovalConfigByTopic | EnsureCommentRemovalConfigByContent;
type EnsureIssueResult = 'updated' | 'created';
type RepoSortMethod = 'alpha' | 'created' | 'created_at' | 'updated' | 'updated_at' | 'size' | 'id' | null;
type SortMethod = 'asc' | 'desc' | null;
interface AutodiscoverConfig {
  topics?: string[];
  sort?: RepoSortMethod;
  order?: SortMethod;
  includeMirrors?: boolean;
  namespaces?: string[];
  projects?: string[];
}
interface FileOwnerRule {
  usernames: string[];
  pattern: string;
  score: number;
  match: (path: string) => boolean;
}
interface Platform {
  /**
   * Whether this is an experimental Platform.
   *
   * Experimental features might be changed or even removed at any time.
   */
  experimental?: true;
  findIssue(title: string): Promise<Issue | null>;
  getIssueList(): Promise<Issue[]>;
  getIssue?(number: number, memCache?: boolean): Promise<Issue | null>;
  getVulnerabilityAlerts?(): Promise<VulnerabilityAlert[]>;
  getRawFile(fileName: string, repoName?: string, branchOrTag?: string): Promise<string | null>;
  getJsonFile(fileName: string, repoName?: string, branchOrTag?: string): Promise<any>;
  initRepo(config: RepoParams): Promise<RepoResult>;
  getPrList(): Promise<Pr[]>;
  ensureIssueClosing(title: string): Promise<void>;
  ensureIssue(issueConfig: EnsureIssueConfig): Promise<EnsureIssueResult | null>;
  massageMarkdown(prBody: string,
  /**
   * Useful for suggesting the use of rebase label when there is no better
   * way, e.g. for Gerrit.
   */

  rebaseLabel?: string): string;
  updatePr(prConfig: UpdatePrConfig): Promise<void>;
  mergePr(config: MergePRConfig): Promise<boolean>;
  addReviewers(number: number, reviewers: string[]): Promise<void>;
  addAssignees(number: number, assignees: string[]): Promise<void>;
  createPr(prConfig: CreatePRConfig): Promise<Pr | null>;
  getRepos(config?: AutodiscoverConfig): Promise<string[]>;
  getBranchForceRebase?(branchName: string): Promise<boolean>;
  deleteLabel(number: number, label: string): Promise<void>;
  addLabel?(number: number, label: string): Promise<void>;
  setBranchStatus(branchStatusConfig: BranchStatusConfig): Promise<void>;
  getBranchStatusCheck(branchName: string, context: string | null | undefined): Promise<BranchStatus | null>;
  ensureCommentRemoval(ensureCommentRemoval: EnsureCommentRemovalConfigByTopic | EnsureCommentRemovalConfigByContent): Promise<void>;
  ensureComment(ensureComment: EnsureCommentConfig): Promise<boolean>;
  getPr(number: number): Promise<Pr | null>;
  findPr(findPRConfig: FindPRConfig): Promise<Pr | null>;
  refreshPr?(number: number): Promise<void>;
  reattemptPlatformAutomerge?(prConfig: ReattemptPlatformAutomergeConfig): Promise<void>;
  getBranchStatus(branchName: string, internalChecksAsSuccess: boolean): Promise<BranchStatus>;
  /**
   * Get the PR for a given branch.
   *
   * @param branchName The source branch name
   * @param targetBranch Optional target branch to prioritize when multiple PRs exist for the
   *   same source branch.
   *
   *   This does not restrict results to PRs targeting this branch. Instead, if
   *   more than one PR matches the given source branch, the one whose target
   *   branch matches `targetBranch` will be preferred.
   *
   *   Only used by Azure and Gerrit platforms currently.
   * @returns The PR object if found, otherwise null.
   */
  getBranchPr(branchName: string, targetBranch?: string): Promise<Pr | null>;
  tryReuseAutoclosedPr?(pr: Pr, newTitle: string): Promise<Pr | null>;
  initPlatform(config: PlatformParams): Promise<PlatformResult>;
  filterUnavailableUsers?(users: string[]): Promise<string[]>;
  commitFiles?(config: CommitFilesConfig): Promise<LongCommitSha | null>;
  expandGroupMembers?(reviewersOrAssignees: string[]): Promise<string[]>;
  extractRulesFromCodeOwnersLines?(cleanedLines: string[]): FileOwnerRule[];
  maxBodyLength(): number;
  labelCharLimit?(): number;
}
interface PlatformScm {
  isBranchBehindBase(branchName: string, baseBranch: string): Promise<boolean>;
  isBranchModified(branchName: string, baseBranch: string): Promise<boolean>;
  isBranchConflicted(baseBranch: string, branch: string): Promise<boolean>;
  branchExists(branchName: string): Promise<boolean>;
  getBranchCommit(branchName: string): Promise<LongCommitSha | null>;
  getBranchUpdateDate(branchName: string): Promise<DateTime | null>;
  deleteBranch(branchName: string): Promise<void>;
  commitAndPush(commitConfig: CommitFilesConfig): Promise<LongCommitSha | null>;
  getFileList(): Promise<string[]>;
  checkoutBranch(branchName: string): Promise<LongCommitSha>;
  mergeToLocal(branchName: string): Promise<void>;
  mergeAndPush(branchName: string): Promise<void>;
  syncForkWithUpstream?(baseBranch: string): Promise<void>;
}
//#endregion
export { AutodiscoverConfig, BranchStatusConfig, CreatePRConfig, EnsureCommentConfig, EnsureCommentRemovalConfig, EnsureCommentRemovalConfigByContent, EnsureCommentRemovalConfigByTopic, EnsureIssueConfig, EnsureIssueResult, FileOwnerRule, FindPRConfig, GitUrlOption, Issue, MergePRConfig, Platform, PlatformParams, PlatformPrOptions, PlatformResult, PlatformScm, Pr, PrBodyStruct, PrDebugData, ReattemptPlatformAutomergeConfig, RepoParams, RepoResult, RepoSortMethod, SortMethod, StatusCheckConfig, UpdatePrConfig, VulnerabilityAlert };
//# sourceMappingURL=types.d.ts.map