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

describe('DC Validator - hot data schema', () => {
  it('should return correct value for col type', () => {
    expect(getHotDataSchema('numeric')).toEqual('')
    expect(
      getHotDataSchema('autocomplete', { data: '', source: [1, 2, 3] })
    ).toEqual(1)
    expect(getHotDataSchema('missing')).toEqual('')
  })

  describe('NOTNULL defaults', () => {
    const dqRules: DQRule[] = [
      {
        BASE_COL: 'TEXT_COL',
        RULE_TYPE: 'NOTNULL',
        RULE_VALUE: 'default_text',
        X: 1
      },
      { BASE_COL: 'NUM_COL', RULE_TYPE: 'NOTNULL', RULE_VALUE: '42', X: 1 }
    ]

    it('should return NOTNULL default for text column', () => {
      expect(getHotDataSchema('text', { data: 'TEXT_COL' }, dqRules)).toEqual(
        'default_text'
      )
    })

    it('should return NOTNULL default as number for numeric column', () => {
      expect(getHotDataSchema('numeric', { data: 'NUM_COL' }, dqRules)).toEqual(
        42
      )
    })

    it('should fall back to type default when no NOTNULL rule exists', () => {
      expect(
        getHotDataSchema('numeric', { data: 'OTHER_COL' }, dqRules)
      ).toEqual('')
    })

    it('should prioritize NOTNULL over autocomplete first option', () => {
      const rulesWithAutocomplete: DQRule[] = [
        {
          BASE_COL: 'SELECT_COL',
          RULE_TYPE: 'NOTNULL',
          RULE_VALUE: 'priority_value',
          X: 1
        },
        {
          BASE_COL: 'SELECT_COL',
          RULE_TYPE: 'HARDSELECT',
          RULE_VALUE: 'ignored',
          X: 1
        }
      ]
      expect(
        getHotDataSchema(
          'autocomplete',
          { data: 'SELECT_COL', source: ['first', 'second'] },
          rulesWithAutocomplete
        )
      ).toEqual('priority_value')
    })
  })
})
