import { type BlameInfo } from "./vcses/git/operations.ts"

export type FileInfo = {
  contents: string,
  lastModified: Date,
  blameLines: Array<BlameInfo>,
}

export type Commit = {
  hash: string,
  message: string,
  isMerge: boolean,
  author: string,
  parent: string | null,
  date: Date,
  diffs: Array<{
    fileName: string,
    lineNumber: number,
    beforeText: string,
    afterText: string,
    added: number,
    removed: number,
  }>
}

// A "ref" is a branch or tag. Branches have some fields that tags
// don't have, but both are a base type of Ref.
export type Ref = {
  name: string,
  sha: string,
  fileList: Set<string>,
}

export type Repository = {
  name: string,
  description?: string,
  cloneUrl: string,
  defaultBranch: string,
  branches: Array<Ref & {
    description?: string,
    ahead: number,
    behind: number,
    compareTo: string,
  }>,
  files: (filename: string, sha: string) => Promise<FileInfo>,
  tags?: Array<Ref>,
  commits?: Map<string, Commit>,
}

export type SortedFileList = Array<{
  name: string,
  fullPath: string,
  isDirectory: boolean,
}>
