"""Add color to asset types (data-driven map/type colors)

Gives AssetType a color column (like AssetStatus) so the map's top-level type
colors come from data instead of the hardcoded map in mapColors.js. Seeds the
four base types with the exact colors that were hardcoded, so nothing changes
visually until someone edits them.

Revision ID: 7d07_assettype_color
Revises: 7d06_typecolor_to_hex
Create Date: 2026-07-08

"""
from alembic import op
import sqlalchemy as sa


revision = '7d07_assettype_color'
down_revision = '7d06_typecolor_to_hex'
branch_labels = None
depends_on = None


SEED = {
    'equipment': '#F44336',
    'computer': '#2196F3',
    'printer': '#4CAF50',
    'network_device': '#FF9800',
}


def upgrade():
    op.add_column('assettypes', sa.Column('color', sa.String(length=20), nullable=True))
    conn = op.get_bind()
    for assettype, hexcolor in SEED.items():
        conn.execute(
            sa.text("UPDATE assettypes SET color = :c WHERE assettype = :t AND (color IS NULL OR color = '')"),
            {'c': hexcolor, 't': assettype}
        )


def downgrade():
    op.drop_column('assettypes', 'color')
