-- Step 39: Add customer avatar fields
-- Feature: Generated customer profile avatars
-- Date: 2026-04-29
--
-- Stores the selected avatar source. Generated avatars keep a deterministic
-- style/seed pair; avatarUrl is reserved for a later controlled upload flow.

SET @column_exists := (
  SELECT COUNT(*)
  FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'customerUsers'
    AND COLUMN_NAME = 'avatarType'
);

SET @sql := IF(
  @column_exists = 0,
  'ALTER TABLE `customerUsers`
     ADD COLUMN `avatarType` varchar(20) NOT NULL DEFAULT ''initials'' AFTER `defaultLanguage`,
     ADD COLUMN `avatarStyle` varchar(40) DEFAULT NULL AFTER `avatarType`,
     ADD COLUMN `avatarSeed` varchar(120) DEFAULT NULL AFTER `avatarStyle`,
     ADD COLUMN `avatarUrl` varchar(500) DEFAULT NULL AFTER `avatarSeed`',
  'SELECT ''customerUsers avatar fields already exist'' AS message'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
