CREATE TABLE "ai_artifact_translations" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" uuid NOT NULL,
	"artifact_id" uuid NOT NULL,
	"language" text NOT NULL,
	"content" text NOT NULL,
	"source_content_hash" text NOT NULL,
	"translation_source" text NOT NULL,
	"review_status" text DEFAULT 'pending' NOT NULL,
	"reviewed_by_id" uuid,
	"reviewed_at" timestamp with time zone,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "ai_artifact_translations_artifact_language_unique" UNIQUE("artifact_id","language")
);
--> statement-breakpoint
CREATE TABLE "ticket_message_translations" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" uuid NOT NULL,
	"message_id" uuid NOT NULL,
	"language" text NOT NULL,
	"body" text NOT NULL,
	"source_body_hash" text NOT NULL,
	"translation_source" text NOT NULL,
	"review_status" text DEFAULT 'pending' NOT NULL,
	"reviewed_by_id" uuid,
	"reviewed_at" timestamp with time zone,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "ticket_message_translations_message_language_unique" UNIQUE("message_id","language")
);
--> statement-breakpoint
CREATE TABLE "knowledge_entry_translations" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" uuid NOT NULL,
	"entry_id" uuid NOT NULL,
	"language" text NOT NULL,
	"title" text NOT NULL,
	"body_markdown" text NOT NULL,
	"flat_markdown" text NOT NULL,
	"source_revision_number" integer NOT NULL,
	"source_body_hash" text NOT NULL,
	"translation_source" text NOT NULL,
	"review_status" text DEFAULT 'pending' NOT NULL,
	"reviewed_by_id" uuid,
	"reviewed_at" timestamp with time zone,
	"created_by_id" uuid,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "knowledge_entry_translations_entry_language_unique" UNIQUE("entry_id","language")
);
--> statement-breakpoint
ALTER TABLE "ai_artifact_translations" ADD CONSTRAINT "ai_artifact_translations_tenant_id_tenants_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenants"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ai_artifact_translations" ADD CONSTRAINT "ai_artifact_translations_artifact_id_ai_artifacts_id_fk" FOREIGN KEY ("artifact_id") REFERENCES "public"."ai_artifacts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ai_artifact_translations" ADD CONSTRAINT "ai_artifact_translations_reviewed_by_id_users_id_fk" FOREIGN KEY ("reviewed_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ticket_message_translations" ADD CONSTRAINT "ticket_message_translations_tenant_id_tenants_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenants"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ticket_message_translations" ADD CONSTRAINT "ticket_message_translations_message_id_ticket_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."ticket_messages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ticket_message_translations" ADD CONSTRAINT "ticket_message_translations_reviewed_by_id_users_id_fk" FOREIGN KEY ("reviewed_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "knowledge_entry_translations" ADD CONSTRAINT "knowledge_entry_translations_tenant_id_tenants_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenants"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "knowledge_entry_translations" ADD CONSTRAINT "knowledge_entry_translations_entry_id_knowledge_entries_id_fk" FOREIGN KEY ("entry_id") REFERENCES "public"."knowledge_entries"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "knowledge_entry_translations" ADD CONSTRAINT "knowledge_entry_translations_reviewed_by_id_users_id_fk" FOREIGN KEY ("reviewed_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "knowledge_entry_translations" ADD CONSTRAINT "knowledge_entry_translations_created_by_id_users_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "ai_artifact_translations_tenant_idx" ON "ai_artifact_translations" USING btree ("tenant_id","artifact_id");--> statement-breakpoint
CREATE INDEX "ticket_message_translations_tenant_idx" ON "ticket_message_translations" USING btree ("tenant_id","message_id");--> statement-breakpoint
CREATE INDEX "knowledge_entry_translations_tenant_idx" ON "knowledge_entry_translations" USING btree ("tenant_id","entry_id");