-- Add spreader settings for granular applications
-- This allows storing different spreader settings for various equipment brands

CREATE TABLE IF NOT EXISTS spreader_settings (
    id SERIAL PRIMARY KEY,
    spreader_brand VARCHAR(100) NOT NULL,
    spreader_model VARCHAR(100),
    setting_value VARCHAR(10) NOT NULL,
    application_rate_description VARCHAR(200),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Add some common spreader settings from the LESCO example
INSERT INTO spreader_settings (spreader_brand, spreader_model, setting_value, application_rate_description) VALUES
('LESCO', 'All Rotary Models', '#14', '1 lb nitrogen per 1000 sq ft'),
('PermaGreen', NULL, '14', '1 lb nitrogen per 1000 sq ft'),
('Cyclone', NULL, '4', '1 lb nitrogen per 1000 sq ft'),
('Spyker', NULL, '4', '1 lb nitrogen per 1000 sq ft'),
('Z-Spray', NULL, '4', '1 lb nitrogen per 1000 sq ft'),
('Vicon', 'LESCO Pendulum', '20', '1 lb nitrogen per 1000 sq ft');

-- Add spreader setting field to user equipment for spreaders
ALTER TABLE user_equipment 
ADD COLUMN IF NOT EXISTS spreader_setting VARCHAR(10),
ADD COLUMN IF NOT EXISTS spreader_brand VARCHAR(100);

-- Create index for better performance
CREATE INDEX IF NOT EXISTS idx_spreader_settings_brand ON spreader_settings(spreader_brand);
CREATE INDEX IF NOT EXISTS idx_user_equipment_spreader ON user_equipment(spreader_brand);

SELECT 'Added spreader settings support successfully!' as migration_status;