# Generated by Django 5.2.11 on 2026-02-09 16:37

import django.core.validators
from django.db import migrations
from django.db import models


def clamp_applicationconfiguration_integer_fields(apps, schema_editor):
    # Clamp barcode_dpi, barcode_max_pages, image_dpi and pages because of
    # PositiveIntegerField --> PositiveSmallIntegerField
    ApplicationConfiguration = apps.get_model("paperless", "ApplicationConfiguration")
    ApplicationConfiguration.objects.filter(barcode_dpi__gt=32767).update(
        barcode_dpi=32767,
    )
    ApplicationConfiguration.objects.filter(barcode_max_pages__gt=32767).update(
        barcode_max_pages=32767,
    )
    ApplicationConfiguration.objects.filter(image_dpi__gt=32767).update(image_dpi=32767)
    ApplicationConfiguration.objects.filter(pages__gt=32767).update(pages=32767)


class Migration(migrations.Migration):
    dependencies = [
        ("paperless", "0006_applicationconfiguration_barcode_tag_split"),
    ]

    operations = [
        migrations.RunPython(
            clamp_applicationconfiguration_integer_fields,
            migrations.RunPython.noop,
        ),
        migrations.AlterField(
            model_name="applicationconfiguration",
            name="barcode_dpi",
            field=models.PositiveSmallIntegerField(
                null=True,
                validators=[django.core.validators.MinValueValidator(1)],
                verbose_name="Sets the barcode DPI",
            ),
        ),
        migrations.AlterField(
            model_name="applicationconfiguration",
            name="barcode_max_pages",
            field=models.PositiveSmallIntegerField(
                null=True,
                validators=[django.core.validators.MinValueValidator(1)],
                verbose_name="Sets the maximum pages for barcode",
            ),
        ),
        migrations.AlterField(
            model_name="applicationconfiguration",
            name="image_dpi",
            field=models.PositiveSmallIntegerField(
                null=True,
                validators=[django.core.validators.MinValueValidator(1)],
                verbose_name="Sets image DPI fallback value",
            ),
        ),
        migrations.AlterField(
            model_name="applicationconfiguration",
            name="pages",
            field=models.PositiveSmallIntegerField(
                null=True,
                validators=[django.core.validators.MinValueValidator(1)],
                verbose_name="Do OCR from page 1 to this value",
            ),
        ),
    ]
