import { RenameId } from "../utils/mongoDB/types.js";
import { User } from "./user.types.js";
import { Plan } from "./plan.types.js";
import { Document, Model, ObjectIdToString, Types } from "mongoose";

//#region src/types/organization.types.d.ts

/**
 * SSO Provider Type - defines the type of SSO provider
 */
type SSOProviderType = 'saml' | 'oidc';
/**
 * SAML Configuration for SSO
 */
type SAMLConfig = {
  /** The URL where the IdP receives SAML requests */
  idpEntityId: string;
  /** The URL where the IdP sends SAML responses (SSO URL) */
  idpSSOUrl: string;
  /** The IdP's public certificate for signature verification (PEM format) */
  idpCertificate: string;
  /** Optional: IdP Single Logout URL */
  idpSLOUrl?: string;
};
/**
 * OIDC Configuration for SSO
 */
type OIDCConfig = {
  /** The OIDC issuer URL (e.g., https://accounts.google.com) */
  issuer: string;
  /** OAuth2 Client ID */
  clientId: string;
  /** OAuth2 Client Secret */
  clientSecret: string;
  /** OAuth2 scopes to request */
  scopes?: string[];
  /** Optional: Authorization endpoint override */
  authorizationEndpoint?: string;
  /** Optional: Token endpoint override */
  tokenEndpoint?: string;
  /** Optional: User info endpoint override */
  userinfoEndpoint?: string;
};
/**
 * SSO Configuration for an Organization
 */
type SSOConfig = {
  /** Whether SSO is enabled for this organization */
  enabled: boolean;
  /** The type of SSO provider */
  providerType?: SSOProviderType;
  /** Unique provider ID for this organization's SSO */
  providerId?: string;
  /** Domain(s) associated with this SSO provider (e.g., 'company.com') */
  domains?: string[];
  /** SAML-specific configuration */
  samlConfig?: SAMLConfig;
  /** OIDC-specific configuration */
  oidcConfig?: OIDCConfig;
  /** Whether to enforce SSO for all users in this organization */
  enforceSSO?: boolean;
  /** Whether to allow users to bypass SSO with password login */
  allowPasswordLogin?: boolean;
};
type OrganizationCreationData = {
  name: Organization['name'];
  ssoConfig?: SSOConfig;
};
type OrganizationData = {
  name: string;
  membersIds: User['id'][];
  adminsIds: User['id'][];
  ssoConfig?: SSOConfig;
};
type Organization = OrganizationData & {
  id: Types.ObjectId;
  creatorId: User['id'];
  plan?: Plan;
  createdAt: number;
  updatedAt: number;
};
type OrganizationAPI = ObjectIdToString<Organization>;
type OrganizationSchema = RenameId<Organization>;
type OrganizationModelType = Model<Organization>;
type OrganizationDocument = Document<unknown, {}, Organization> & Organization;
//#endregion
export { OIDCConfig, Organization, OrganizationAPI, OrganizationCreationData, OrganizationData, OrganizationDocument, OrganizationModelType, OrganizationSchema, SAMLConfig, SSOConfig, SSOProviderType };
//# sourceMappingURL=organization.types.d.ts.map