/*
Phase 21J.3 demand illustration style consistency marker.

This does not queue generation or regenerate the library. It marks existing
demand-generated character illustrations produced before template 21J.3 so the
admin can deliberately regenerate them with the corrected art direction.
*/

UPDATE dbo.IllustrationLibraryItems
SET MetadataJson = JSON_MODIFY(
        JSON_MODIFY(
            JSON_MODIFY(
                CASE WHEN ISJSON(MetadataJson) = 1 THEN MetadataJson ELSE N'{}' END,
                '$.generationSource',
                N'Demand generation'),
            '$.styleReview',
            N'Needs 21J.3 regeneration'),
        '$.styleIntent',
        N'match-approved-starter-library'),
    AdminNotes = CONCAT(
        COALESCE(NULLIF(AdminNotes, N''), N''),
        CASE WHEN NULLIF(AdminNotes, N'') IS NULL THEN N'' ELSE N' ' END,
        N'Phase 21J.3: demand-generated before the 21J.3 style template; regenerate with the current template before approval.'),
    UpdatedUtc = SYSUTCDATETIME()
WHERE StableCode LIKE N'char-demand-%'
  AND Status IN (N'Generated', N'Approved')
  AND ISNULL(PromptTemplateVersion, N'') <> N'21J.3'
  AND (AdminNotes IS NULL OR AdminNotes NOT LIKE N'%Phase 21J.3:%');
