import type { Visibility } from '@/core/module-registry/types';

// ---------------------------------------------------------------------------
// Block system
// ---------------------------------------------------------------------------

export type BlockType =
  | 'role'
  | 'context'
  | 'task'
  | 'constraints'
  | 'format'
  | 'checklist'
  | 'validation'
  | 'output-schema'
  | 'custom';

export interface PromptBlock {
  id: string;
  type: BlockType;
  label: string;
  content: string;
  order: number;
  required: boolean;
  conditional?: {
    variableId: string;
    operator: 'equals' | 'notEquals' | 'truthy' | 'falsy';
    value?: string;
  };
}

// ---------------------------------------------------------------------------
// Variable system
// ---------------------------------------------------------------------------

export type VariableType =
  | 'text'
  | 'number'
  | 'select'
  | 'multi-select'
  | 'boolean'
  | 'tag-selector'
  | 'project-selector'
  | 'company-selector'
  | 'tone-selector'
  | 'regulation-set-selector';

export interface SelectOption {
  value: string;
  label: string;
}

export interface PromptVariable {
  id: string;
  label: string;
  type: VariableType;
  required: boolean;
  defaultValue?: unknown;
  placeholder?: string;
  helperText?: string;
  options?: SelectOption[];
  validation?: {
    min?: number;
    max?: number;
    pattern?: string;
  };
}

// ---------------------------------------------------------------------------
// Output & provider
// ---------------------------------------------------------------------------

export type OutputMode =
  | 'short'
  | 'expanded-expert'
  | 'step-by-step'
  | 'chain-of-thought'
  | 'structured-json'
  | 'checklist';

export type PromptCategory =
  | 'architecture'
  | 'legal'
  | 'technical'
  | 'administrative'
  | 'gis'
  | 'bim'
  | 'rendering'
  | 'procurement'
  | 'general';

export type PromptDomain =
  | 'architecture-visualization'
  | 'technical-documentation'
  | 'legal-review'
  | 'urbanism-gis'
  | 'bim-coordination'
  | 'procurement-bidding'
  | 'administrative-writing'
  | 'general';

export interface ProviderProfile {
  id: string;
  name: string;
  maxLength?: number;
  formattingPreference: 'markdown' | 'plain' | 'structured';
  instructionStyle: 'direct' | 'conversational' | 'system-prompt';
  verbosityLevel: 'concise' | 'standard' | 'detailed';
}

// ---------------------------------------------------------------------------
// Safety blocks
// ---------------------------------------------------------------------------

export interface SafetyBlock {
  id: string;
  label: string;
  content: string;
  enabled: boolean;
  category: 'legal' | 'tone' | 'citation' | 'disclaimer';
}

// ---------------------------------------------------------------------------
// Template
// ---------------------------------------------------------------------------

export interface PromptTemplate {
  id: string;
  name: string;
  category: PromptCategory;
  domain: PromptDomain;
  description: string;
  targetAiType: 'text' | 'image' | 'code' | 'review' | 'rewrite';
  blocks: PromptBlock[];
  variables: PromptVariable[];
  outputMode: OutputMode;
  providerProfile?: string;
  safetyBlocks?: SafetyBlock[];
  tags: string[];
  version: string;
  author: string;
  visibility: Visibility;
  exampleOutputs?: string[];
  metadata?: Record<string, unknown>;
}

// ---------------------------------------------------------------------------
// History
// ---------------------------------------------------------------------------

export interface PromptHistoryEntry {
  id: string;
  templateId: string;
  templateName: string;
  templateVersion: string;
  values: Record<string, unknown>;
  composedPrompt: string;
  outputMode: OutputMode;
  providerProfile: string | null;
  safetyBlocks: string[];
  tags: string[];
  isFavorite: boolean;
  createdAt: string;
  metadata?: Record<string, unknown>;
}
