{
  "name": "@tsdiapi/prisma",
  "description": "A TSDIAPI plugin for database management using Prisma ORM with adapter support.",
  "postInstall": "npx prisma init",
  "afterInstall": {
    "command": "npx prisma init",
    "when": "true"
  },
  "registration": {
    "pluginImportName": "PrismaPlugin",
    "pluginArgs": "{ client: prismaClient, prismaOptions: { transactionOptions: { timeout: 15000 } } }",
    "imports": [
      "import { PrismaClient } from '@generated/prisma/client.js'",
      "import { PrismaPg } from '@prisma/adapter-pg'",
      "import { Pool } from 'pg'"
    ],
    "code": [
      "/**",
      " * Create PrismaClient with adapter for Prisma 7.0+",
      " * ",
      " * IMPORTANT: Configuration split in Prisma 7:",
      " * 1. prisma.config.ts - Used ONLY by Prisma CLI commands:",
      " *    - DATABASE_URL: for migrations, studio, db push/pull",
      " *    - shadowDatabaseUrl: ONLY for 'prisma migrate' (creates temp DB for testing migrations)",
      " * ",
      " * 2. This runtime client:",
      " *    - Does NOT read prisma.config.ts",
      " *    - Does NOT need shadowDatabaseUrl (that's only for migrations)",
      " *    - Only needs main DATABASE_URL for actual database connections",
      " *    - Must explicitly create adapter (required in Prisma 7)",
      " */",
      "function createPrismaClient(): PrismaClient {",
      "  const databaseUrl = process.env.DATABASE_URL;",
      "  if (!databaseUrl) {",
      "    throw new Error('DATABASE_URL is not set');",
      "  }",
      "  const pool = new Pool({ connectionString: databaseUrl });",
      "  const adapter = new PrismaPg(pool);",
      "  return new PrismaClient({ adapter });",
      "}",
      "const prismaClient = createPrismaClient();"
    ]
  },
  "requiredPackages": [
    "@prisma/client",
    "@prisma/adapter-pg",
    "pg"
  ],
  "prisma": {
    "required": true,
    "scripts": [
      {
        "command": "ADD MODEL Tsdiapi ({version Int});",
        "description": "Add a sample Prisma model."
      },
      {
        "command": "UPDATE GENERATOR client (output='../src/generated/prisma');",
        "description": "Update the Prisma client generator."
      }
    ]
  },
  "variables": [
    {
      "name": "DATABASE_TYPE",
      "type": "string",
      "default": "PostgreSQL",
      "configurable": true,
      "description": "Select your database type",
      "inquirer": {
        "type": "list",
        "message": "Choose your database type:",
        "choices": [
          "PostgreSQL",
          "MySQL",
          "SQLite",
          "SQL Server"
        ]
      }
    },
    {
      "name": "DATABASE_URL",
      "type": "string",
      "default": "",
      "configurable": true,
      "description": "Database connection string",
      "inquirer": {
        "message": "Enter your database connection string:",
        "required": true
      }
    },
    {
      "name": "SHADOW_DATABASE_URL",
      "type": "string",
      "default": "",
      "configurable": true,
      "description": "Shadow database connection string for safe migrations (optional)",
      "inquirer": {
        "message": "Enter your shadow database URL (optional, for migrations):",
        "required": false,
        "when": "DATABASE_TYPE === 'PostgreSQL' || DATABASE_TYPE === 'MySQL'"
      }
    }
  ],
  "generators": [
    {
      "name": "event",
      "description": "Generate a Prisma event listener.",
      "files": [
        {
          "source": "generators/event/*.*",
          "destination": ".",
          "isHandlebarsTemplate": true
        }
      ],
      "args": [
        {
          "name": "modelName",
          "description": "Prisma model name (e.g., 'User', 'Order').",
          "inquirer": {
            "type": "input",
            "message": "Enter the Prisma model name:"
          },
          "validate": {
            "type": "string",
            "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
            "errorMessage": "Model name must be a valid identifier."
          },
          "transform": "capitalize(x)"
        },
        {
          "name": "operation",
          "description": "Prisma operation type.",
          "inquirer": {
            "type": "list",
            "message": "Select the Prisma operation:",
            "choices": [
              "FindUnique",
              "FindUniqueOrThrow",
              "FindFirst",
              "FindFirstOrThrow",
              "FindMany",
              "Create",
              "CreateMany",
              "Delete",
              "Update",
              "DeleteMany",
              "UpdateMany",
              "Upsert",
              "Aggregate",
              "GroupBy",
              "Count"
            ]
          }
        }
      ],
      "postMessages": [
        "✅ Event listener generated successfully!"
      ]
    },
    {
      "name": "hook",
      "description": "Generate a Prisma operation hook.",
      "files": [
        {
          "source": "generators/hook/*.*",
          "destination": ".",
          "isHandlebarsTemplate": true
        }
      ],
      "args": [
        {
          "name": "modelName",
          "description": "Prisma model name (e.g., 'User', 'Order').",
          "inquirer": {
            "type": "input",
            "message": "Enter the Prisma model name:"
          },
          "validate": {
            "type": "string",
            "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
            "errorMessage": "Model name must be a valid identifier."
          },
          "transform": "capitalize(x)"
        },
        {
          "name": "operation",
          "description": "Prisma operation type.",
          "inquirer": {
            "type": "list",
            "message": "Select the Prisma operation:",
            "choices": [
              "FindUnique",
              "FindUniqueOrThrow",
              "FindFirst",
              "FindFirstOrThrow",
              "FindMany",
              "Create",
              "CreateMany",
              "Delete",
              "Update",
              "DeleteMany",
              "UpdateMany",
              "Upsert",
              "Aggregate",
              "GroupBy",
              "Count"
            ]
          }
        }
      ],
      "postMessages": [
        "✅ Operation hook generated successfully!"
      ]
    }
  ],
  "postMessages": [
    "✅ Prisma setup complete with adapter support!",
    "❗ IMPORTANT: Prisma 7.0+ requires adapters for database connections",
    "📝 Configuration files:",
    "  - prisma/prisma.config.ts - CLI configuration (migrations, studio)",
    "  - src/main.ts - Runtime client with adapter",
    "❗❗ Open 'prisma/schema.prisma' and define your models! ❗❗",
    "⚡ Run 'npm run prisma:generate' to regenerate the Prisma client.",
    "🔄 Run 'npm run prisma:migrate' to apply migrations."
  ]
}