import { Domain, OrgVersionType } from '../../index.js';
import { IHomepageApplicationV2Dto } from '../application/index.js';
import { Billing } from '../billing/index.js';
import { GroupBrief } from '../group/index.js';
import { PluginExecutionVersions } from '../plugin/index.js';
import { Profile } from '../profile/index.js';
import { Agent, AgentType } from './agent.js';

export const SUPERBLOCKS_CLOUD_AGENT_ORG_NAME = 'cloudagent.superblocks';
// for server tests (V2 orgs)
export const SUPERBLOCKS_TEST_ORG_NAME = 'superblocksservertest.com';
// for server tests (V2 orgs)
export const SUPERBLOCKS_TEST_ORG_NAME2 = 'superblocksservertest2.com';
// for server tests (V1 orgs)
export const SUPERBLOCKS_TEST_ORG_V1_NAME = 'superblocksservertest-orgv1.com';
// for server tests (V1 orgs)
export const SUPERBLOCKS_TEST_ORG_V1_NAME2 = 'superblocksservertest2-orgv1.com';
// for manual testing
export const SUPERBLOCKS_MANUAL_TEST_ORG_NAME = 'superblockstest.com';
export const SUPERBLOCKS_SUPPORT = 'Superblocks Support';
export const SUPERBLOCKS_SUPPORT_EMAIL = 'support@superblocks.com';

export const VISITOR_ORG_NAME = 'visitor';
export const VISITOR_ORG_ID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';

/**
 * Snapshot of the org's app-inference configuration, embedded on `/me` so the UI
 * bootstrap gets it without a second round trip to
 * `/api/v1/organizations/:id/app-inference-configuration`.
 *
 * Tri-state semantics on `Organization.appInferenceConfiguration`:
 *   - `undefined` → feature unavailable (gate flag off for the org)
 *   - `null`      → feature available, admin has not configured anything
 *   - populated   → feature available, admin has configured a preferred integration
 */
export interface OrganizationAppInferenceConfiguration {
  preferredIntegrationId: string;
  updatedBy: string | null;
  updated: string;
}

export interface Organization {
  id: string;
  name: string;
  domains?: Domain[];
  agents?: Agent[];
  apiKey: string;
  agentType: AgentType;
  minExternalAgentVersion: string;
  pluginExecutionVersions?: PluginExecutionVersions;
  groups: GroupBrief[];
  billing: Billing;
  profiles?: Profile[];
  created: Date;
  version?: OrgVersionType;
  appInferenceConfiguration?: OrganizationAppInferenceConfiguration | null;
}

export type OrgBriefDto = {
  id: string;
  name: string;
};

export interface IOrganizationDto {
  id: string;
  name: string;
  email: string;
  slug: string;
  logoUrl: string;
  new: boolean;
  userPermissions: string[];

  agents: Agent[] | undefined;
  pluginExecutionVersions: PluginExecutionVersions;
  minExternalAgentVersion: string;
  version?: OrgVersionType;
}

export interface IOrganizationApplicationsV2Dto {
  organization: IOrganizationDto;
  applications: IHomepageApplicationV2Dto[];
}

export * from './addUser.js';
export * from './agent.js';
export * from './invite.js';
export * from './token.js';
