"""
Type stubs for _taper_slice Fortran extension module.

This module provides Python type hints for the f2py compiled Fortran module.
"""

from typing import Tuple
import numpy as np
from numpy.typing import NDArray

def taper_calculate(
    d1: float,
    d2: float,
    rl: float,
    alfa: float,
    q: float,
    tilt: float,
    m1: int,
    n_slice: int,
    m2: int,
    dr1: float,
    fai: float,
    curveq: float,
) -> Tuple[
    NDArray[np.float64],  # p: Contact center stress for each slice (MPa)
    NDArray[np.float64],  # a: Contact half-width for each slice (mm)
    NDArray[np.float64],  # q_slice: Contact force for each slice (N)
    float,                 # dc: Roller deflection (mm)
    float,                 # q1: Equilibrium load (N)
    float,                 # qm: Equilibrium moment (N·mm)
    int,                   # ierr: Error code (0=success)
]:
    """Calculate slice stress distribution for roller-raceway contact
    
    Uses the Influence Coefficient Method to calculate contact stress.
    
    Args:
        d1: Roller small-end diameter (mm)
        d2: Roller large-end diameter (mm), d1=d2 for cylindrical roller
        rl: Roller effective length (mm)
        alfa: Roller half-cone angle (deg), alfa=0 for cylindrical roller
        q: Roller load (N)
        tilt: Roller tilt angle (deg)
        m1: Crown type - 0:straight, 1:arc, 2:logarithmic
        n_slice: Number of slices (1-50)
        m2: Raceway type - 0:plane, 1:inner, 2:outer
        dr1: Raceway diameter (mm), use negative value for outer ring
        fai: Raceway half-cone angle (deg)
        curveq: Design load (N), for logarithmic crown calculation
    
    Returns:
        Tuple containing:
        - p: Contact center stress array (MPa), shape=(n_slice,)
        - a: Contact half-width array (mm), shape=(n_slice,)
        - q_slice: Contact force array (N), shape=(n_slice,)
        - dc: Roller deflection (mm)
        - q1: Equilibrium load (N), should be close to input load q
        - qm: Equilibrium moment (N·mm)
        - ierr: Error code
            - 0: Calculation successful
            - 1: Equation solving failed
            - 2: Invalid slice count (n_slice < 1 or > 50)
            - 3: Invalid load (q <= 0)
    
    Example:
        >>> import _taper_slice
        >>> p, a, q_slice, dc, q1, qm, ierr = _taper_slice.taper_calculate(
        ...     d1=10.0, d2=10.0, rl=9.6, alfa=0.0,
        ...     q=1340.86, tilt=0.0, m1=2, n_slice=30,
        ...     m2=2, dr1=-150.0, fai=0.0, curveq=14100.0
        ... )
        >>> print(f"Max stress: {max(p):.0f} MPa")
        >>> print(f"Slice force sum: {sum(q_slice):.2f} N")
    
    Note:
        - Outer ring raceway (m2=2) dr1 should use negative value (Hertz contact sign convention)
        - Logarithmic crown (m1=2) achieves uniform stress distribution when q=curveq
        - Recommended n_slice >= 20 for sufficient accuracy
    """
    ...


class taper_slice_mod:
    """Fortran module taper_slice_mod
    
    Contains the core calculation subroutines for slice stress analysis.
    Usually not called directly; use taper_calculate instead.
    """
    
    # Module constants
    POISSON: float
    """Poisson's ratio (default: 0.3)"""
    
    ELASTIC_MOD: float
    """Elastic modulus in MPa (default: 2.06e5)"""
    
    PI: float
    """Pi constant"""
    
    DEG2RAD: float
    """Degree to radian conversion factor"""
    
    MAX_SLICES: int
    """Maximum number of slices (50)"""
    
    @staticmethod
    def calculate_slice_stress(
        d1: float,
        d2: float,
        rl: float,
        alfa: float,
        q: float,
        tilt: float,
        m1: int,
        n_slice: int,
        m2: int,
        dr1: float,
        fai: float,
        curveq: float,
        pl: float,
        rc: float,
    ) -> Tuple[
        NDArray[np.float64],  # p: Contact center stress for each slice (MPa)
        NDArray[np.float64],  # a: Contact half-width for each slice (mm)
        NDArray[np.float64],  # q_slice: Contact force for each slice (N)
        float,                 # dc: Roller deflection (mm)
        float,                 # q1: Equilibrium load (N)
        float,                 # qm: Equilibrium moment (N·mm)
        int,                   # ierr: Error code (0=success)
    ]:
        """Full interface for slice stress calculation (includes arc crown params)
        
        This is the full interface including arc crown parameters pl and rc.
        For most use cases, use taper_calculate instead which provides defaults.
        
        Additional Args:
            pl: Parallel length (mm), only for arc crown (m1=1)
            rc: Crown radius (mm), only for arc crown (m1=1)
        """
        ...
