DO $$ BEGIN
 CREATE TYPE "scenario_type" AS ENUM('unit', 'building');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "solar_scenario" (
	"id" bigserial PRIMARY KEY NOT NULL,
	"solar_id" bigint NOT NULL,
	"scenario_type" "scenario_type" NOT NULL,
	"number_panels" integer NOT NULL,
	"array_kwhp" integer NOT NULL,
	"lifetime_dc_kwh" real NOT NULL,
	"yearly_dc_kwh" real NOT NULL,
	"lifetime_ac_kwh" real,
	"yearly_ac_kwh" real,
	"cost" real NOT NULL,
	"expected_payback_years" real,
	"panelled_roof_area" real NOT NULL,
	"is_default" boolean NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "solar_scenario" ADD CONSTRAINT "solar_scenario_solar_id_solar_id_fk" FOREIGN KEY ("solar_id") REFERENCES "solar"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
