-- Migration: Add pending_photos table for photo uploads
-- This table tracks photos uploaded by users that are pending admin approval
-- Run this in the punimtag_auth database

CREATE TABLE IF NOT EXISTS pending_photos (
  id SERIAL PRIMARY KEY,
  user_id INTEGER NOT NULL,
  filename VARCHAR(255) NOT NULL,
  original_filename VARCHAR(255) NOT NULL,
  file_path TEXT NOT NULL,
  file_size INTEGER NOT NULL,
  mime_type VARCHAR(100) NOT NULL,
  status VARCHAR(50) DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'rejected')),
  submitted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  reviewed_at TIMESTAMP,
  reviewed_by INTEGER,
  rejection_reason TEXT,
  
  CONSTRAINT fk_pending_photos_user 
    FOREIGN KEY (user_id) 
    REFERENCES users(id) 
    ON DELETE CASCADE
);

-- Create indexes for efficient queries
CREATE INDEX IF NOT EXISTS idx_pending_photos_user_id ON pending_photos(user_id);
CREATE INDEX IF NOT EXISTS idx_pending_photos_status ON pending_photos(status);
CREATE INDEX IF NOT EXISTS idx_pending_photos_submitted_at ON pending_photos(submitted_at);

-- Add comment to table
COMMENT ON TABLE pending_photos IS 'Stores photos uploaded by users that are pending admin approval';

