/*
  Warnings:

  - You are about to drop the `AiAgent` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `AiPlugin` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `AiTool` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `ToolCall` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "AiPlugin" DROP CONSTRAINT "AiPlugin_agent_id_fkey";

-- DropForeignKey
ALTER TABLE "AiTool" DROP CONSTRAINT "AiTool_agent_id_fkey";

-- DropForeignKey
ALTER TABLE "ToolCall" DROP CONSTRAINT "ToolCall_tool_id_fkey";

-- DropTable
DROP TABLE "AiAgent";

-- DropTable
DROP TABLE "AiPlugin";

-- DropTable
DROP TABLE "AiTool";

-- DropTable
DROP TABLE "ToolCall";

-- CreateTable
CREATE TABLE "Plugin" (
    "id" TEXT NOT NULL,
    "openapi" TEXT NOT NULL,
    "info" JSONB NOT NULL DEFAULT '{}',
    "servers" TEXT[],
    "paths" JSONB NOT NULL DEFAULT '{}',
    "agent_id" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "Agent" (
    "id" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "instructions" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "url" TEXT NOT NULL,
    "key_id" TEXT NOT NULL,
    "categories" TEXT[],
    "image" TEXT,
    "account_id" TEXT,
    "repo" TEXT,
    "email" TEXT,
    "verified" BOOLEAN NOT NULL DEFAULT false,
    "tool_ids" TEXT[],

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

-- CreateTable
CREATE TABLE "Tool" (
    "id" TEXT NOT NULL,
    "agent_id" TEXT NOT NULL,
    "execution" JSONB NOT NULL,
    "function" JSONB NOT NULL,
    "type" TEXT NOT NULL,
    "verified" BOOLEAN NOT NULL DEFAULT false,

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

-- CreateTable
CREATE TABLE "Toolcall" (
    "id" SERIAL NOT NULL,
    "tool_id" TEXT NOT NULL,
    "call_timestamp" TIMESTAMP(3) NOT NULL,

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

-- AddForeignKey
ALTER TABLE "Plugin" ADD CONSTRAINT "Plugin_agent_id_fkey" FOREIGN KEY ("agent_id") REFERENCES "Agent"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tool" ADD CONSTRAINT "Tool_agent_id_fkey" FOREIGN KEY ("agent_id") REFERENCES "Agent"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Toolcall" ADD CONSTRAINT "Toolcall_tool_id_fkey" FOREIGN KEY ("tool_id") REFERENCES "Tool"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
