-- CreateSchema
CREATE SCHEMA IF NOT EXISTS "public";

-- CreateTable
CREATE TABLE "offers" (
    "id" SERIAL NOT NULL,
    "uuid" TEXT NOT NULL,
    "team_uuid" VARCHAR(100) NOT NULL,
    "status" VARCHAR(20) NOT NULL DEFAULT 'active',
    "workflow_status" VARCHAR(20) NOT NULL DEFAULT 'pending',
    "workflow_error" TEXT,
    "location_uuid" VARCHAR(100),
    "location_name" VARCHAR(255) NOT NULL DEFAULT '',
    "location_country" VARCHAR(100) NOT NULL DEFAULT '',
    "location_country_code" VARCHAR(10) NOT NULL DEFAULT '',
    "location_latitude" DOUBLE PRECISION,
    "location_longitude" DOUBLE PRECISION,
    "product_uuid" VARCHAR(100) NOT NULL,
    "product_name" VARCHAR(255) NOT NULL,
    "category_name" VARCHAR(255) NOT NULL DEFAULT '',
    "quantity" DECIMAL(12,2) NOT NULL,
    "unit" VARCHAR(20) NOT NULL DEFAULT 'ton',
    "price_per_unit" DECIMAL(12,2) NOT NULL,
    "currency" VARCHAR(10) NOT NULL DEFAULT 'USD',
    "terminus_schema_id" VARCHAR(255),
    "terminus_document_id" VARCHAR(255),
    "description" TEXT,
    "valid_until" DATE,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "offers_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "calculations" (
    "id" SERIAL NOT NULL,
    "uuid" TEXT NOT NULL,
    "product_uuid" VARCHAR(100) NOT NULL,
    "quantity" DECIMAL(12,2) NOT NULL,
    "source_location_uuid" VARCHAR(100) NOT NULL,
    "user_id" VARCHAR(255) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "calculations_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "suppliers" (
    "id" SERIAL NOT NULL,
    "uuid" TEXT NOT NULL,
    "team_uuid" VARCHAR(100) NOT NULL,
    "kyc_profile_uuid" VARCHAR(100),
    "name" VARCHAR(255) NOT NULL,
    "description" TEXT,
    "country" VARCHAR(100) NOT NULL DEFAULT '',
    "country_code" VARCHAR(10) NOT NULL DEFAULT '',
    "logo_url" VARCHAR(500),
    "latitude" DOUBLE PRECISION,
    "longitude" DOUBLE PRECISION,
    "is_verified" BOOLEAN NOT NULL DEFAULT false,
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "suppliers_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "offers_uuid_key" ON "offers"("uuid");

-- CreateIndex
CREATE UNIQUE INDEX "calculations_uuid_key" ON "calculations"("uuid");

-- CreateIndex
CREATE UNIQUE INDEX "suppliers_uuid_key" ON "suppliers"("uuid");

-- CreateIndex
CREATE UNIQUE INDEX "suppliers_team_uuid_key" ON "suppliers"("team_uuid");

