from decimal import Decimal
from django.core.exceptions import ValidationError
from django.test import SimpleTestCase

from apps.imports.services import _date, _decimal, _month


class ImportPrimitiveValidationTests(SimpleTestCase):
    def test_valid_iso_date(self):
        self.assertEqual(str(_date('2026-09-15', 'Joining Date')), '2026-09-15')

    def test_invalid_date_has_field_error(self):
        with self.assertRaises(ValidationError):
            _date('15/09/2026', 'Joining Date')

    def test_month_normalizes_to_first_day(self):
        self.assertEqual(str(_month('2026-09', 'Payroll Month')), '2026-09-01')

    def test_negative_money_is_rejected(self):
        with self.assertRaises(ValidationError):
            _decimal('-1', 'Amount')

    def test_positive_money_is_decimal(self):
        self.assertEqual(_decimal('1250.50', 'Amount', allow_zero=False), Decimal('1250.50'))
