-- Migration 003: Add stock support to coins table
-- Adds asset_type discriminator and stock-specific columns

-- Add asset_type ENUM column
ALTER TABLE coins
  ADD COLUMN asset_type ENUM('crypto','stock') NOT NULL DEFAULT 'crypto' AFTER is_active;

-- Add stock-specific columns
ALTER TABLE coins
  ADD COLUMN sector VARCHAR(100) DEFAULT NULL AFTER asset_type,
  ADD COLUMN sub_sector VARCHAR(100) DEFAULT NULL AFTER sector,
  ADD COLUMN lot_size INT NOT NULL DEFAULT 1 AFTER sub_sector,
  ADD COLUMN listing_date DATE DEFAULT NULL AFTER lot_size;

-- Index for asset_type filtering (mode switcher)
CREATE INDEX idx_coins_asset_type ON coins(asset_type);

-- ── New stock-related settings ──
-- These are seeded via seed_data.py but included here for completeness
-- INSERT IGNORE INTO app_settings (setting_key, setting_value, category, description)
-- VALUES
--   ('stock_buy_fee_pct', '0.15', 'fees', 'Fee beli saham (%) - Growin default'),
--   ('stock_sell_fee_pct', '0.25', 'fees', 'Fee jual saham (%) - Growin default'),
--   ('stock_sell_tax_pct', '0.10', 'fees', 'PPh Final jual saham (0.10%)'),
--   ('stock_broker', '"growin"', 'fees', 'Broker saham aktif (growin/stockbit/ajaib)'),
--   ('stock_icon_source', '"growin"', 'data_source', 'Sumber icon saham (growin/stockbit)'),
--   ('stock_data_source', '"yahoo"', 'data_source', 'Sumber data saham'),
--   ('stock_sync_timeframes', '["1D","1W"]', 'data_source', 'Timeframe sync saham');
