-- ============================================================
-- NordaBiz - Migration: Add GBP Hours and Photos Columns
-- ============================================================
-- Created: 2026-01-08
-- Description:
--   - Adds google_opening_hours (JSONB) for storing opening hours from Google Places API
--   - Adds google_photos_count (INTEGER) for storing photos count from Google Places API
--   - These columns enable the GBP audit service to properly check hours and photos completeness
--
-- Usage:
--   PostgreSQL: psql -h localhost -U nordabiz_app -d nordabiz -f add_gbp_hours_photos_columns.sql
--   SQLite: Not fully supported (JSONB columns)
-- ============================================================

-- ============================================================
-- 1. ADD GOOGLE OPENING HOURS COLUMN
-- ============================================================

ALTER TABLE company_website_analysis
ADD COLUMN IF NOT EXISTS google_opening_hours JSONB;

COMMENT ON COLUMN company_website_analysis.google_opening_hours IS 'Opening hours from Google Places API: weekday_text array, open_now, periods';

-- ============================================================
-- 2. ADD GOOGLE PHOTOS COUNT COLUMN
-- ============================================================

ALTER TABLE company_website_analysis
ADD COLUMN IF NOT EXISTS google_photos_count INTEGER;

COMMENT ON COLUMN company_website_analysis.google_photos_count IS 'Number of photos from Google Places API (max 10 from free tier)';

-- ============================================================
-- 3. GRANT PERMISSIONS TO APPLICATION USER
-- ============================================================

-- Ensure nordabiz_app has permissions on the table
GRANT ALL ON TABLE company_website_analysis TO nordabiz_app;

-- ============================================================
-- MIGRATION COMPLETE
-- ============================================================

-- Verify migration (PostgreSQL only)
DO $$
BEGIN
    RAISE NOTICE 'GBP Hours/Photos columns migration completed successfully!';
    RAISE NOTICE 'Added columns to company_website_analysis:';
    RAISE NOTICE '  - google_opening_hours (JSONB) - Opening hours from Google Places API';
    RAISE NOTICE '  - google_photos_count (INTEGER) - Photos count from Google Places API';
    RAISE NOTICE 'Granted permissions to nordabiz_app';
END $$;
