export type TradeSide = 'BUY' | 'SELL';

export type OrderStatus =
    | 'pending_new'
    | 'partially_filled'
    | 'filled'
    | 'canceled'
    | 'expired'
    | 'rejected'
    | 'unknown';

export type OrderAction = 'ENTRY' | 'EXIT';

export type OrderType = 'Market' | 'Limit' | 'Stop';

export function normalizeTradeSide(side: string): TradeSide {
    const normalized = (side || '').trim().toUpperCase();
    if (normalized === 'SELL' || normalized === 'SHORT') return 'SELL';
    return 'BUY';
}

export function normalizeOrderStatus(status: string): OrderStatus {
    const normalized = (status || '').trim().toLowerCase();
    if (normalized === 'filled') return 'filled';
    if (normalized === 'partially_filled' || normalized === 'partial_fill' || normalized === 'partiallyfilled') return 'partially_filled';
    if (normalized === 'canceled' || normalized === 'cancelled') return 'canceled';
    if (normalized === 'expired') return 'expired';
    if (normalized === 'rejected') return 'rejected';
    if (normalized === 'unknown') return 'unknown';
    return 'pending_new';
}

export function normalizeOrderAction(action?: string): OrderAction | undefined {
    const normalized = (action || '').trim().toUpperCase();
    if (normalized === 'ENTRY' || normalized === 'EXIT') return normalized;
    return undefined;
}

export function normalizeOrderType(type: string): OrderType {
    const normalized = (type || '').trim().toLowerCase();
    if (normalized === 'limit') return 'Limit';
    if (normalized === 'stop') return 'Stop';
    return 'Market';
}
