import { HotColumnSettings } from '../models/dc-validation.model'

/**
 * Parses a single column's `COLTYPE` JSON-object string (one per `cols` row,
 * as of the vertical-array getdata.sas fix — see issue #253). Unlike the
 * previous comma-joined `sasparams.COLTYPE` format, each row is independent:
 * a malformed or missing value here only drops that one column's rule,
 * rather than every column's.
 *
 * @param coltype a single column's COLTYPE JSON string, or undefined (the
 *   LEFT JOIN in getdata.sas can leave it unset for unmatched rows)
 */
export const parseColTypeRow = (
  coltype: string | undefined
): HotColumnSettings | undefined => {
  if (!coltype) return undefined

  try {
    return JSON.parse(coltype)
  } catch (err: any) {
    return undefined
  }
}
