export type AuthenticationType = 'password' | 'private_key';

export type DeployAction = 'push' | 'pushAndDeploy' | 'deploy' | 'localDeploy';

// Project as returned by the API (snake_case). `password` / `ssh_private_key`
// come back as the literal strings "set" / "not set", never the secret value.
export interface Project {
  action?: DeployAction | null;
  authentication_type?: AuthenticationType;
  branch?: string;
  classic_policy_set?: boolean;
  id: number;
  is_deployed_locally?: boolean;
  is_local?: boolean;
  name: string;
  password?: string;
  pushed_at?: string | null;
  repository_url?: string;
  ssh_key_id?: number | null;
  ssh_private_key?: string;
  username?: string;
}

// Form model (camelCase) used while creating/editing a project.
export interface ProjectFormValues {
  authenticationType: AuthenticationType;
  branch: string;
  classicPolicySet: boolean;
  name: string;
  password: string;
  repositoryUrl: string;
  sshKeyId: number | null;
  sshPrivateKey: string;
  username: string;
}

export interface ProjectListResponse {
  data: Project[];
  meta?: { total?: number };
}

export interface VcsSyncStatus {
  deployedLocally: boolean;
  isSynchronised: boolean;
}

export interface SshKey {
  id: number;
  public_key: string;
}

export interface ModuleAuthor {
  image: string;
  name: string;
}

export interface ModuleVersionInfo {
  latest?: boolean;
}

export interface Module {
  author: ModuleAuthor;
  commit?: string;
  description: string;
  downloads: number;
  name: string;
  readme?: string;
  repo?: string;
  subdirectory?: string;
  tag?: string;
  updated: string | number;
  version: string;
  versions: Record<string, ModuleVersionInfo>;
}

export interface ModulesListResponse {
  data: Module[];
  meta: { total: number };
}

// A module already added to a project (from /build_app/projects/modules/:id).
export interface AddedModule {
  availableVersion?: string;
  encodedName?: string;
  input?: [];
  isExternal?: boolean;
  name: string;
  version?: string;
}
