-- Migration: Add no-show tracking columns to matches table
-- Date: 2026-02-23
-- Description: Adds columns for no-show policy feature

-- Add no-show tracking columns (idempotent)
DO $$
BEGIN
  IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'matches' AND column_name = 'no_show') THEN
    ALTER TABLE matches ADD COLUMN no_show boolean DEFAULT false NOT NULL;
  END IF;

  IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'matches' AND column_name = 'no_show_reported_at') THEN
    ALTER TABLE matches ADD COLUMN no_show_reported_at timestamptz;
  END IF;

  IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'matches' AND column_name = 'no_show_reported_by') THEN
    ALTER TABLE matches ADD COLUMN no_show_reported_by uuid REFERENCES auth.users(id);
  END IF;
END $$;

-- Index for querying no-show workers (admin review)
CREATE INDEX IF NOT EXISTS idx_matches_no_show ON matches(no_show) WHERE no_show = true;

COMMENT ON COLUMN matches.no_show IS 'Worker flagged as no-show by contractor';
COMMENT ON COLUMN matches.no_show_reported_at IS 'When the no-show was reported';
COMMENT ON COLUMN matches.no_show_reported_by IS 'Profile ID of who reported the no-show';
