import { DQRule } from '../models/dq-rules.model'
import { getColumnDefault } from '../utils/getColumnDefault'

describe('DC Validator - getColumnDefault', () => {
  const dqRules: DQRule[] = [
    { BASE_COL: 'NOTNULL_COL', RULE_TYPE: 'NOTNULL', RULE_VALUE: 'nn', X: 1 },
    { BASE_COL: 'READONLY_COL', RULE_TYPE: 'READONLY', RULE_VALUE: 'ro', X: 1 },
    { BASE_COL: 'HIDDEN_COL', RULE_TYPE: 'HIDDEN', RULE_VALUE: 'hd', X: 1 },
    { BASE_COL: 'NUM_COL', RULE_TYPE: 'READONLY', RULE_VALUE: '42', X: 1 },
    { BASE_COL: 'EMPTY_COL', RULE_TYPE: 'HIDDEN', RULE_VALUE: '  ', X: 1 },
    { BASE_COL: 'OTHER_COL', RULE_TYPE: 'HARDSELECT', RULE_VALUE: 'x', X: 1 }
  ]

  it('should return defaults for NOTNULL, READONLY and HIDDEN rules', () => {
    expect(getColumnDefault('NOTNULL_COL', dqRules, 'text')).toEqual('nn')
    expect(getColumnDefault('READONLY_COL', dqRules, 'text')).toEqual('ro')
    expect(getColumnDefault('HIDDEN_COL', dqRules, 'text')).toEqual('hd')
  })

  it('should coerce to number for numeric columns', () => {
    expect(getColumnDefault('NUM_COL', dqRules, 'numeric')).toEqual(42)
  })

  it('should return string for numeric columns when value is non-numeric', () => {
    expect(getColumnDefault('READONLY_COL', dqRules, 'numeric')).toEqual('ro')
  })

  it('should ignore empty RULE_VALUE', () => {
    expect(getColumnDefault('EMPTY_COL', dqRules, 'text')).toBeUndefined()
  })

  it('should return undefined for rules that do not provide defaults', () => {
    expect(getColumnDefault('OTHER_COL', dqRules, 'text')).toBeUndefined()
  })

  it('should return undefined for non-existent columns and empty rules', () => {
    expect(getColumnDefault('MISSING', dqRules, 'text')).toBeUndefined()
    expect(getColumnDefault('NOTNULL_COL', [], 'text')).toBeUndefined()
  })
})
