import { RenameId } from "../utils/mongoDB/types.js";
import { User, UserAPI } from "./user.types.js";
import { Organization, OrganizationAPI } from "./organization.types.js";
import { Document, Model, ObjectIdToString, Types } from "mongoose";
import { IntlayerConfig } from "@intlayer/types/config";
import { Token } from "oauth2-server";

//#region src/types/project.types.d.ts
type ProjectCreationData = {
  name: Project['name'];
};
type ProjectConfigInternationalization = Partial<Pick<IntlayerConfig['internationalization'], 'locales' | 'defaultLocale'>>;
type ProjectConfigEditor = Partial<Pick<IntlayerConfig['editor'], 'applicationURL' | 'cmsURL'>>;
type ProjectConfigAI = Partial<Pick<IntlayerConfig['ai'], 'provider' | 'model' | 'apiKey' | 'applicationContext' | 'baseURL'>> & {
  apiKeyConfigured?: boolean;
};
type Webhook = {
  id?: string;
  name: string;
  url: string;
  enabled: boolean;
  secret?: string;
};
type ProjectConfigCI = {
  autoTriggerBuilds?: boolean;
  webhooks?: Webhook[];
};
type ProjectConfiguration = {
  internationalization?: ProjectConfigInternationalization;
  editor?: ProjectConfigEditor;
  ai?: ProjectConfigAI;
};
type RepositoryProvider = 'github' | 'gitlab' | 'bitbucket';
type BaseRepository = {
  provider: RepositoryProvider;
  owner: string;
  repository: string;
  branch: string;
  url: string;
  configFilePath: string;
};
type GitHubRepository = BaseRepository & {
  provider: 'github';
  installationId?: number;
};
type GitLabRepository = BaseRepository & {
  provider: 'gitlab';
  projectId?: number; /** Custom GitLab instance URL (e.g., https://gitlab.company.com) */
  instanceUrl?: string;
};
type BitbucketRepository = BaseRepository & {
  provider: 'bitbucket';
  workspace: string;
};
type RepositoryConnection = GitHubRepository | GitLabRepository | BitbucketRepository;
type ProjectData = {
  organizationId: Organization['id'];
  name: string;
  membersIds: User['id'][];
  adminsIds: User['id'][];
  creatorId: User['id'];
  configuration?: ProjectConfiguration;
  repository?: RepositoryConnection;
  webhooks?: ProjectConfigCI; /** Screenshot of the application URL, generated automatically when applicationURL is set */
  imageUrl?: string;
};
type AccessKeyData = {
  name: string;
  grants: string[];
  expiresAt?: Date;
};
type OAuth2AccessData = AccessKeyData & {
  clientId: string;
  clientSecret: string;
  accessToken: string[];
  userId: User['id'];
};
type OAuth2AccessContext = {
  accessToken: Token;
  user?: UserAPI;
  project?: ProjectAPI;
  organization?: OrganizationAPI;
  grants: Token['grants'];
};
type OAuth2Access = OAuth2AccessData & {
  id: Types.ObjectId;
  createdAt: number;
  updatedAt: number;
};
type OAuth2AccessAPI = ObjectIdToString<OAuth2Access>;
type Project = ProjectData & {
  id: Types.ObjectId;
  createdAt: number;
  updatedAt: number;
  oAuth2Access: OAuth2Access[];
};
type ProjectAPI = ObjectIdToString<Project>;
type ProjectSchema = RenameId<Project>;
type ProjectModelType = Model<Project>;
type ProjectDocument = Document<unknown, {}, Project> & Project;
//#endregion
export { AccessKeyData, BaseRepository, BitbucketRepository, GitHubRepository, GitLabRepository, OAuth2Access, OAuth2AccessAPI, OAuth2AccessContext, OAuth2AccessData, Project, ProjectAPI, ProjectConfigCI, ProjectConfiguration, ProjectCreationData, ProjectData, ProjectDocument, ProjectModelType, ProjectSchema, RepositoryConnection, RepositoryProvider, Webhook };
//# sourceMappingURL=project.types.d.ts.map