CREATE SCHEMA "pokemon";
--> statement-breakpoint
CREATE TABLE "pokemon"."cards" (
	"card_id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "pokemon"."cards_card_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
	"product_id" integer NOT NULL,
	"variant" varchar(100) NOT NULL,
	"product_name" varchar(255),
	"product_line_name" varchar(255),
	"product_url_name" varchar(255) DEFAULT '' NOT NULL,
	"rarity_name" varchar(100),
	"sealed" boolean DEFAULT false NOT NULL,
	"set_id" integer,
	"card_type" varchar(100),
	"energy_type" varchar(100),
	"number" varchar(50),
	"artist" varchar(255)
);
--> statement-breakpoint
CREATE TABLE "pokemon"."inventory" (
	"inventory_id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
	"user_id" varchar(100) NOT NULL,
	"catalog_name" varchar(100),
	"card_id" integer NOT NULL,
	"condition" varchar(255) NOT NULL,
	"quantity" integer,
	"purchase_price" numeric(10,2),
	"note" varchar(255)
);
--> statement-breakpoint
CREATE TABLE "pokemon"."price_history" (
	"sku_id" integer,
	"calculated_at" timestamp,
	"market_price" numeric(10,2),
	CONSTRAINT "pk_price_history" PRIMARY KEY("sku_id","calculated_at")
);
--> statement-breakpoint
CREATE TABLE "pokemon"."processing_skus" (
	"sku_id" integer PRIMARY KEY
);
--> statement-breakpoint
CREATE TABLE "pokemon"."sales_history" (
	"sku_id" integer,
	"order_date" timestamp,
	"title" varchar(255),
	"custom_listing_id" varchar(255),
	"language" varchar(100),
	"listing_type" varchar(100),
	"purchase_price" numeric(10,2),
	"quantity" integer,
	"shipping_price" numeric(10,2),
	CONSTRAINT "pk_sales_history" PRIMARY KEY("sku_id","order_date")
);
--> statement-breakpoint
CREATE TABLE "pokemon"."sets" (
	"set_id" integer PRIMARY KEY,
	"set_name" varchar(255) NOT NULL,
	"set_url_name" varchar(255) NOT NULL,
	"set_code" varchar(100) NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pokemon"."skus" (
	"sku_id" integer PRIMARY KEY,
	"card_id" integer DEFAULT 0 NOT NULL,
	"product_id" integer NOT NULL,
	"condition" varchar(255) NOT NULL,
	"language" varchar(100) NOT NULL,
	"variant" varchar(100) NOT NULL,
	"calculated_at" timestamp,
	"highest_price" numeric(10,2),
	"lowest_price" numeric(10,2),
	"market_price" numeric(10,2),
	"price_count" integer
);
--> statement-breakpoint
CREATE TABLE "pokemon"."tcg_overrides" (
	"product_id" integer PRIMARY KEY,
	"product_name" varchar(255),
	"product_line_name" varchar(255),
	"product_url_name" varchar(255) DEFAULT '' NOT NULL,
	"rarity_name" varchar(100),
	"sealed" boolean DEFAULT false NOT NULL,
	"set_id" integer,
	"card_type" varchar(100),
	"energy_type" varchar(100),
	"number" varchar(50),
	"artist" varchar(255)
);
--> statement-breakpoint
CREATE TABLE "pokemon"."tcg_cards" (
	"product_id" integer PRIMARY KEY,
	"product_name" varchar(255) NOT NULL,
	"product_line_name" varchar(255) DEFAULT '' NOT NULL,
	"product_line_url_name" varchar(255) DEFAULT '' NOT NULL,
	"product_status_id" integer DEFAULT 0 NOT NULL,
	"product_type_id" integer DEFAULT 0 NOT NULL,
	"product_url_name" varchar(255) DEFAULT '' NOT NULL,
	"rarity_name" varchar(100) DEFAULT '' NOT NULL,
	"sealed" boolean DEFAULT false NOT NULL,
	"seller_listable" boolean DEFAULT false NOT NULL,
	"set_id" integer,
	"shipping_category_id" integer,
	"duplicate" boolean DEFAULT false NOT NULL,
	"foil_only" boolean DEFAULT false NOT NULL,
	"max_fulfillable_quantity" integer,
	"total_listings" integer,
	"score" numeric(10,2),
	"lowest_price" numeric(10,2),
	"lowest_price_with_shipping" numeric(10,2),
	"market_price" numeric(10,2),
	"median_price" numeric(10,2),
	"attack1" varchar(1024),
	"attack2" varchar(1024),
	"attack3" varchar(1024),
	"attack4" varchar(1024),
	"card_type" varchar(100),
	"card_type_b" varchar(100),
	"energy_type" varchar(100),
	"flavor_text" varchar(1000),
	"hp" integer,
	"number" varchar(50) DEFAULT '' NOT NULL,
	"release_date" timestamp,
	"resistance" varchar(100),
	"retreat_cost" varchar(100),
	"stage" varchar(100),
	"weakness" varchar(100),
	"artist" varchar(255)
);
--> statement-breakpoint
CREATE INDEX "idx_card_product_id" ON "pokemon"."cards" ("product_id","variant");--> statement-breakpoint
CREATE INDEX "idx_userid_cardid" ON "pokemon"."inventory" ("user_id","card_id");--> statement-breakpoint
CREATE INDEX "idx_product_id_condition" ON "pokemon"."skus" ("product_id","variant","condition");--> statement-breakpoint
CREATE INDEX "idx_card_id_condition" ON "pokemon"."skus" ("card_id","condition");