# Generated by Django 5.2.5 on 2026-01-12 14:35

import django_migrate_sql.operations
from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ("models", "12542_update_file_list_default_config"),
    ]

    operations = [
        migrations.operations.special.SeparateDatabaseAndState(
            state_operations=[
                django_migrate_sql.operations.CreateSQL(
                    name="__arches_get_nodevalue_label",
                    sql="\nCREATE OR REPLACE FUNCTION public.__arches_get_nodevalue_label(\n    node_value jsonb,\n    in_nodeid uuid,\n    language_id text DEFAULT 'en')\n    RETURNS text\n    LANGUAGE 'plpgsql'\n    COST 100\n    VOLATILE PARALLEL UNSAFE\nAS $BODY$\n    declare\n        return_label         text := '';\n        nodevalue_tileid     text;\n        value_nodeid         text;\n    begin\n\n        if node_value is null or in_nodeid is null then\n            return '';\n        end if;\n\n        select n.config ->> 'nodeid'\n        into value_nodeid\n        from nodes n\n        where n.nodeid = in_nodeid::uuid;\n\n        select __arches_get_node_display_value(t.tiledata, value_nodeid, language_id)\n        into return_label\n        from tiles t\n        where t.tileid = node_value::uuid;\n        \n        if return_label is null then\n            return_label := '';\n        end if;\n        \n    return return_label;\n    end;                \n$BODY$;\n",
                    reverse_sql="drop function __arches_get_nodevalue_label;",
                ),
                django_migrate_sql.operations.CreateSQL(
                    name="__arches_get_node_display_value",
                    sql="\nCREATE OR REPLACE FUNCTION public.__arches_get_node_display_value(\n    in_tiledata jsonb,\n    in_nodeid uuid,\n    language_id text DEFAULT 'en')\n    RETURNS text\n    LANGUAGE 'plpgsql'\n    COST 100\n    VOLATILE PARALLEL UNSAFE\nAS $BODY$\n    declare\n        display_value   text := '';\n        in_node_type    text;\n        in_node_config  json;\n    begin\n        if in_nodeid is null or in_nodeid is null then\n            return '<invalid_nodeid>';\n        end if;\n\n        if in_tiledata is null then\n            return '';\n        end if;\n\n        select n.datatype, n.config\n        into in_node_type, in_node_config\n        from nodes n where nodeid = in_nodeid::uuid;\n\n        if in_node_type in ('semantic', 'geojson-feature-collection', 'annotation') then\n            return 'unsupported node type (' || in_node_type || ')';\n        end if;\n\n        if in_node_type is null then\n            return '';\n        end if;\n\n        case in_node_type\n            when 'string' then\n                display_value := ((in_tiledata -> in_nodeid::text) -> language_id) ->> 'value';\n            when 'concept' then\n                display_value := __arches_get_concept_label((in_tiledata ->> in_nodeid::text)::uuid);\n            when 'concept-list' then\n                display_value := __arches_get_concept_list_label(in_tiledata -> in_nodeid::text);\n            when 'edtf' then\n                display_value := (in_tiledata ->> in_nodeid::text);\n            when 'file-list' then\n                display_value := __arches_get_file_list_label(in_tiledata -> in_nodeid::text, language_id);\n            when 'domain-value' then\n                display_value := __arches_get_domain_label((in_tiledata ->> in_nodeid::text)::uuid, in_nodeid, language_id);\n            when 'domain-value-list' then\n                display_value := __arches_get_domain_list_label(in_tiledata -> in_nodeid::text, in_nodeid, language_id);\n            when 'url' then\n                display_value := ((in_tiledata -> in_nodeid::text)::jsonb ->> 'url');\n            when 'node-value' then\n                display_value := __arches_get_nodevalue_label(in_tiledata -> in_nodeid::text, in_nodeid);\n            when 'resource-instance' then\n                display_value := __arches_get_resourceinstance_label(in_tiledata -> in_nodeid::text, 'name', language_id);\n            when 'resource-instance-list' then\n                display_value := __arches_get_resourceinstance_list_label(in_tiledata -> in_nodeid::text, 'name', language_id);\n            else\n                display_value := (in_tiledata ->> in_nodeid::text)::text;\n\n            end case;\n\n        return display_value;\n    end;\n$BODY$;\n",
                    reverse_sql="drop function __arches_get_node_display_value;",
                ),
            ],
        ),
        django_migrate_sql.operations.AlterSQL(
            name="__arches_get_nodevalue_label",
            sql="\nDROP FUNCTION IF EXISTS public.__arches_get_nodevalue_label(jsonb, uuid, text);\n\nCREATE OR REPLACE FUNCTION public.__arches_get_nodevalue_label(\n    node_value uuid,\n    in_nodeid uuid,\n    language_id text DEFAULT 'en')\n    RETURNS text\n    LANGUAGE 'plpgsql'\n    COST 100\n    VOLATILE PARALLEL UNSAFE\nAS $BODY$\n    declare\n        return_label         text := '';\n        nodevalue_tileid     text;\n        value_nodeid         uuid;\n    begin\n\n        if node_value is null or in_nodeid is null then\n            return '';\n        end if;\n\n        select n.config ->> 'nodeid'\n        into value_nodeid\n        from nodes n\n        where n.nodeid = in_nodeid;\n\n        select __arches_get_node_display_value(t.tiledata, value_nodeid, language_id)\n        into return_label\n        from tiles t\n        where t.tileid = node_value;\n        \n        if return_label is null then\n            return_label := '';\n        end if;\n        \n    return return_label;\n    end;                \n$BODY$;\n",
            reverse_sql="\nDROP FUNCTION IF EXISTS public.__arches_get_nodevalue_label(uuid, uuid, text);\n\nCREATE OR REPLACE FUNCTION public.__arches_get_nodevalue_label(\n    node_value jsonb,\n    in_nodeid uuid,\n    language_id text DEFAULT 'en')\n    RETURNS text\n    LANGUAGE 'plpgsql'\n    COST 100\n    VOLATILE PARALLEL UNSAFE\nAS $BODY$\n    declare\n        return_label         text := '';\n        nodevalue_tileid     text;\n        value_nodeid         text;\n    begin\n\n        if node_value is null or in_nodeid is null then\n            return '';\n        end if;\n\n        select n.config ->> 'nodeid'\n        into value_nodeid\n        from nodes n\n        where n.nodeid = in_nodeid::uuid;\n\n        select __arches_get_node_display_value(t.tiledata, value_nodeid, language_id)\n        into return_label\n        from tiles t\n        where t.tileid = node_value::uuid;\n        \n        if return_label is null then\n            return_label := '';\n        end if;\n        \n    return return_label;\n    end;                \n$BODY$;\n",
            state_reverse_sql="drop function __arches_get_nodevalue_label;",
        ),
        django_migrate_sql.operations.AlterSQL(
            name="__arches_get_node_display_value",
            sql="\nCREATE OR REPLACE FUNCTION public.__arches_get_node_display_value(\n    in_tiledata jsonb,\n    in_nodeid uuid,\n    language_id text DEFAULT 'en')\n    RETURNS text\n    LANGUAGE 'plpgsql'\n    COST 100\n    VOLATILE PARALLEL UNSAFE\nAS $BODY$\n    declare\n        display_value   text := '';\n        in_node_type    text;\n        in_node_config  json;\n    begin\n        if in_nodeid is null or in_nodeid is null then\n            return '<invalid_nodeid>';\n        end if;\n\n        if in_tiledata is null then\n            return '';\n        end if;\n\n        select n.datatype, n.config\n        into in_node_type, in_node_config\n        from nodes n where nodeid = in_nodeid::uuid;\n\n        if in_node_type in ('semantic', 'geojson-feature-collection', 'annotation') then\n            return 'unsupported node type (' || in_node_type || ')';\n        end if;\n\n        if in_node_type is null then\n            return '';\n        end if;\n\n        case in_node_type\n            when 'string' then\n                display_value := ((in_tiledata -> in_nodeid::text) -> language_id) ->> 'value';\n            when 'concept' then\n                display_value := __arches_get_concept_label((in_tiledata ->> in_nodeid::text)::uuid);\n            when 'concept-list' then\n                display_value := __arches_get_concept_list_label(in_tiledata -> in_nodeid::text);\n            when 'edtf' then\n                display_value := (in_tiledata ->> in_nodeid::text);\n            when 'file-list' then\n                display_value := __arches_get_file_list_label(in_tiledata -> in_nodeid::text, language_id);\n            when 'domain-value' then\n                display_value := __arches_get_domain_label((in_tiledata ->> in_nodeid::text)::uuid, in_nodeid, language_id);\n            when 'domain-value-list' then\n                display_value := __arches_get_domain_list_label(in_tiledata -> in_nodeid::text, in_nodeid, language_id);\n            when 'url' then\n                display_value := ((in_tiledata -> in_nodeid::text)::jsonb ->> 'url');\n            when 'node-value' then\n                display_value := __arches_get_nodevalue_label((in_tiledata -> in_nodeid::text)::uuid, in_nodeid, language_id);\n            when 'resource-instance' then\n                display_value := __arches_get_resourceinstance_label(in_tiledata -> in_nodeid::text, 'name', language_id);\n            when 'resource-instance-list' then\n                display_value := __arches_get_resourceinstance_list_label(in_tiledata -> in_nodeid::text, 'name', language_id);\n            else\n                display_value := (in_tiledata ->> in_nodeid::text)::text;\n\n            end case;\n\n        return display_value;\n    end;\n$BODY$;\n",
            reverse_sql="\nCREATE OR REPLACE FUNCTION public.__arches_get_node_display_value(\n    in_tiledata jsonb,\n    in_nodeid uuid,\n    language_id text DEFAULT 'en')\n    RETURNS text\n    LANGUAGE 'plpgsql'\n    COST 100\n    VOLATILE PARALLEL UNSAFE\nAS $BODY$\n    declare\n        display_value   text := '';\n        in_node_type    text;\n        in_node_config  json;\n    begin\n        if in_nodeid is null or in_nodeid is null then\n            return '<invalid_nodeid>';\n        end if;\n\n        if in_tiledata is null then\n            return '';\n        end if;\n\n        select n.datatype, n.config\n        into in_node_type, in_node_config\n        from nodes n where nodeid = in_nodeid::uuid;\n\n        if in_node_type in ('semantic', 'geojson-feature-collection', 'annotation') then\n            return 'unsupported node type (' || in_node_type || ')';\n        end if;\n\n        if in_node_type is null then\n            return '';\n        end if;\n\n        case in_node_type\n            when 'string' then\n                display_value := ((in_tiledata -> in_nodeid::text) -> language_id) ->> 'value';\n            when 'concept' then\n                display_value := __arches_get_concept_label((in_tiledata ->> in_nodeid::text)::uuid);\n            when 'concept-list' then\n                display_value := __arches_get_concept_list_label(in_tiledata -> in_nodeid::text);\n            when 'edtf' then\n                display_value := (in_tiledata ->> in_nodeid::text);\n            when 'file-list' then\n                display_value := __arches_get_file_list_label(in_tiledata -> in_nodeid::text, language_id);\n            when 'domain-value' then\n                display_value := __arches_get_domain_label((in_tiledata ->> in_nodeid::text)::uuid, in_nodeid, language_id);\n            when 'domain-value-list' then\n                display_value := __arches_get_domain_list_label(in_tiledata -> in_nodeid::text, in_nodeid, language_id);\n            when 'url' then\n                display_value := ((in_tiledata -> in_nodeid::text)::jsonb ->> 'url');\n            when 'node-value' then\n                display_value := __arches_get_nodevalue_label(in_tiledata -> in_nodeid::text, in_nodeid);\n            when 'resource-instance' then\n                display_value := __arches_get_resourceinstance_label(in_tiledata -> in_nodeid::text, 'name', language_id);\n            when 'resource-instance-list' then\n                display_value := __arches_get_resourceinstance_list_label(in_tiledata -> in_nodeid::text, 'name', language_id);\n            else\n                display_value := (in_tiledata ->> in_nodeid::text)::text;\n\n            end case;\n\n        return display_value;\n    end;\n$BODY$;\n",
            state_reverse_sql="drop function __arches_get_node_display_value;",
        ),
    ]
