// Type definitions for steel beam design

export interface SteelProperties {
  designation: string;
  fy: number; // Steel yield strength (ksi)
  e: number; // Modulus of elasticity (ksi)
  useStiffnessFactor: boolean; // 0.8 for Direct Analysis Method
  depth: number; // in
  width: number; // in
  tw: number; // Web thickness, in
  tf: number; // Flange thickness, in
  sx: number; // Section modulus, in³
  ix: number; // Moment of inertia, in⁴
  zx: number; // Plastic modulus, in³
  weight: number; // lb/ft
}

export type SupportType = 'Pinned' | 'Fixed' | 'Roller';

export interface Span {
  id: number;
  length: number; // ft
}

export interface Support {
  id: number;
  type: SupportType;
}

export interface BeamGeometry {
  numberOfSupports: number;
  spans: Span[];
  supports: Support[];
  leftCantilever: boolean;
  leftCantileverLength: number; // ft
  rightCantilever: boolean;
  rightCantileverLength: number; // ft
}

export interface ConcreteProperties {
  fc: number; // Concrete compressive strength (psi)
  density: number; // pcf
  slabThickness: number; // in
  beamSpacing: number; // ft
  beamPosition: 'Interior' | 'Edge';
}

export interface MetalDeck {
  manufacturer: string;
  type: string;
  orientation: 'Transverse' | 'Longitudinal';
}

export interface ShearStuds {
  diameter: string; // e.g., "3/4""
  length: number; // in
  fu: number; // Tensile strength (ksi)
  studsPerRib: number;
}

export interface CompositeSettings {
  isComposite: boolean;
  temporaryShoring: boolean;
  metalDeck: MetalDeck;
  shearStuds: ShearStuds;
  partialComposite: 'calculated' | 'specified';
  partialCompositePercent?: number;
}

export interface LateralBracing {
  type: 'Continuous (Top)' | 'Continuous (Bottom)' | 'Discrete';
  cbFactor: 'Calculated' | 'User-defined';
  cbValue?: number;
}

export type LoadType = 'Dead' | 'Live' | 'RLive' | 'Snow' | 'Wind' | 'Seismic';

export interface UniformLoad {
  id: string;
  full: boolean;
  start: number; // ft
  end: number; // ft
  tributaryWidth: number; // ft
  dead: number; // psf
  live: number; // psf
  rLive: number; // psf
  snow: number; // psf
  wind: number; // psf
  seismic: number; // psf
}

export interface VariableLoad {
  id: string;
  full: boolean;
  start: number; // ft
  startLoad: number; // psf
  end: number; // ft
  endLoad: number; // psf
  tributaryWidth: number; // ft
  loadType: LoadType;
}

export interface ConcentratedLoad {
  id: string;
  location: number; // ft
  load: number; // kip
  loadType: LoadType;
}

export interface MomentLoad {
  id: string;
  location: number; // ft
  moment: number; // k-ft
  loadType: LoadType;
}

export interface LoadConfig {
  segment: number;
  uniformLoads: UniformLoad[];
  variableLoads: VariableLoad[];
  concentratedLoads: ConcentratedLoad[];
  momentLoads: MomentLoad[];
  calculateSelfweight: boolean;
}

export type DesignMethod = 'ASD' | 'LRFD';
export type LoadCombinationType = 'pre-combined' | 'asdip-combinations';

export interface LoadCombinations {
  type: LoadCombinationType;
  designMethod: DesignMethod;
}

export interface DeflectionResult {
  loadCase: string;
  deflection: number; // in
  lOverD: number;
  limit: number;
  ratio: number;
  pass: boolean;
}

export interface FlexureResult {
  lateralBracing: string;
  maxMoment: number; // k-ft
  cbFactor: number;
  designStrength: number; // k-ft
  ratio: number;
  limitState: string;
  pass: boolean;
}

export interface ShearResult {
  cv: number;
  maxShear: number; // kip
  designStrength: number; // kip
  ratio: number;
  pass: boolean;
}

export interface CompositeFlexureResult {
  shearStudLength: number; // in
  requiredStuds: number;
  partialComposite: number; // %
  maxMoment: number; // k-ft
  designStrength: number; // k-ft
  ratio: number;
  pass: boolean;
}

export interface DesignResults {
  reactions: number[];
  shearValues: number[][];
  momentValues: number[][];
  deflections: DeflectionResult[];
  shear: ShearResult;
  flexureNonComposite: FlexureResult;
  flexureComposite?: CompositeFlexureResult;
  overallPass: boolean;
}

export interface BeamDesignState {
  steel: SteelProperties;
  geometry: BeamGeometry;
  concrete: ConcreteProperties;
  composite: CompositeSettings;
  lateralBracing: LateralBracing;
  loads: LoadConfig;
  loadCombinations: LoadCombinations;
  results?: DesignResults;
  
  // Actions
  setSteelProperties: (steel: Partial<SteelProperties>) => void;
  setGeometry: (geometry: Partial<BeamGeometry>) => void;
  setConcreteProperties: (concrete: Partial<ConcreteProperties>) => void;
  setCompositeSettings: (composite: Partial<CompositeSettings>) => void;
  setLateralBracing: (bracing: Partial<LateralBracing>) => void;
  setLoads: (loads: Partial<LoadConfig>) => void;
  setLoadCombinations: (combinations: Partial<LoadCombinations>) => void;
  calculate: () => void;
}
