import { OrderBy } from '../../types';
import { OrderByOption, OrderByOptionSchema } from '../schemas';

/**
 * Maps an OrderBy object to an OrderByOption object
 *
 * This function transforms an OrderBy input definition into a strongly-typed
 * OrderByOption that can be used by the filter component. It converts the
 * desc boolean flag to a direction string ('asc' or 'desc') and initializes
 * the selected state to false.
 *
 * @param orderBy - The source OrderBy object to map
 * @returns A validated OrderByOption object
 */
export function orderByOptionMapping(orderBy: OrderBy): OrderByOption {
  return OrderByOptionSchema.parse({
    label: orderBy.label,
    by: orderBy.by,
    dir: orderBy.desc ? 'desc' : 'asc',
    selected: false,
  });
}
