-- CreateEnum
CREATE TYPE "TermsCategory" AS ENUM ('DELIVERY', 'DISPATCH', 'INSPECTION', 'TRANSIT_INSURANCE', 'PAYMENT_TERMS');

-- CreateTable
CREATE TABLE "TermsCondition" (
    "id" TEXT NOT NULL,
    "category" "TermsCategory" NOT NULL,
    "text" TEXT NOT NULL,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "TermsCondition_category_idx" ON "TermsCondition"("category");

-- Seed the standard clauses (the prior TC_DEFAULTS) so the catalogue is usable
-- immediately and existing default wording stays selectable.
INSERT INTO "TermsCondition" ("id", "category", "text", "updatedAt") VALUES
  ('tcseed_delivery',  'DELIVERY',          'Within 4 to 5 days',                                            CURRENT_TIMESTAMP),
  ('tcseed_dispatch',  'DISPATCH',          'To be transported to site address as above. Freight Supplier''s A/C', CURRENT_TIMESTAMP),
  ('tcseed_inspect',   'INSPECTION',        'NA',                                                            CURRENT_TIMESTAMP),
  ('tcseed_transit',   'TRANSIT_INSURANCE', 'NA',                                                            CURRENT_TIMESTAMP),
  ('tcseed_payment',   'PAYMENT_TERMS',     'Within 30 days from delivery.',                                 CURRENT_TIMESTAMP);
