<?php

/**
 * Migration 0014 — AI Section Generator support columns
 *
 * Adds five columns to `instinctor_library_sections` so templates can be used
 * by the AI Section Generator:
 *
 *   ai_slots         JSON map of placeholder tokens (e.g. {{h1}}) to slot
 *                    metadata. Each entry: {block, setting, type, max_len,
 *                    required, optional, markdown}. The platform endpoint
 *                    uses this to tell Claude what to generate for each
 *                    template and to validate+sanitize the returned copy.
 *   tone_tags        Space-separated descriptors — "minimal premium quiet",
 *                    "bold punchy energetic", "warm friendly hand-crafted".
 *                    Used by Claude to pick the template that best matches
 *                    the user's brief + store-level brand tone.
 *   industries       Space-separated industry fits — "saas portfolio
 *                    consulting". Empty = universal. Lets Claude narrow the
 *                    candidate set for industry-specific briefs.
 *   ai_enabled       Whether the generator is allowed to emit this template.
 *                    Defaults to 0; only templates explicitly marked with
 *                    {{slot}} placeholders + slot metadata should be flipped
 *                    on. Blocks like contact/login/plans/cart stay off.
 *   preview_thumbnail Path/URL to the card image shown in the Generator's
 *                    template picker (optional — nullable).
 *
 * @since 2.1.247
 */

if (!defined('ABSPATH')) exit;
return [
    'description' => 'AI Section Generator columns on library_sections',

    'up' => [
        "ALTER TABLE {prefix}instinctor_library_sections
            ADD COLUMN ai_slots         longtext     NULL AFTER element_tree,
            ADD COLUMN tone_tags        varchar(255) NOT NULL DEFAULT '' AFTER ai_slots,
            ADD COLUMN industries       varchar(255) NOT NULL DEFAULT '' AFTER tone_tags,
            ADD COLUMN ai_enabled       tinyint(1)   NOT NULL DEFAULT 0 AFTER industries,
            ADD COLUMN preview_thumbnail varchar(512) NOT NULL DEFAULT '' AFTER ai_enabled,
            ADD KEY idx_ai_enabled (ai_enabled)",
    ],

    'down' => [
        "ALTER TABLE {prefix}instinctor_library_sections
            DROP KEY idx_ai_enabled,
            DROP COLUMN preview_thumbnail,
            DROP COLUMN ai_enabled,
            DROP COLUMN industries,
            DROP COLUMN tone_tags,
            DROP COLUMN ai_slots",
    ],
];
