-- Add ski pass amenity and convert EV charging to boolean availability

ALTER TABLE "Listing"
  ADD COLUMN IF NOT EXISTS "hasSkiPass" BOOLEAN NOT NULL DEFAULT false,
  ADD COLUMN IF NOT EXISTS "evChargingAvailable" BOOLEAN NOT NULL DEFAULT false;

-- Backfill evChargingAvailable from legacy enum if present
DO $$
BEGIN
  IF EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_name = 'Listing' AND column_name = 'evCharging'
  ) THEN
    UPDATE "Listing"
    SET "evChargingAvailable" = CASE WHEN "evCharging" IS NULL OR "evCharging" = 'NONE' THEN false ELSE true END;
  END IF;
END $$;

-- Drop legacy enum column/type if present
DO $$
BEGIN
  IF EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_name = 'Listing' AND column_name = 'evCharging'
  ) THEN
    ALTER TABLE "Listing" DROP COLUMN "evCharging";
  END IF;
  IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'EvCharging') THEN
    DROP TYPE "EvCharging";
  END IF;
END $$;
