{
  "info": {
    "_postman_id": "teamcast-platform-admin-002",
    "name": "Teamcast Maya - Platform Admin APIs",
    "description": "Platform Admin API endpoints for Teamcast Maya.\n\nPlatform Admins manage their own tenants, users, and API keys through these endpoints.\n\n**Authentication:** Platform Admin JWT (obtained via POST /platform-admin/auth/login)\n\n**Who uses this:** Platform Admin staff logging into the /login Platform Admin tab to manage their tenants and issue API keys to external systems.\n\n**Note:** Super Admin (Teamcast internal) endpoints are not included here.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{pa_jwt_token}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "http://localhost:3009/api/v1"
    }
  ],
  "item": [
    {
      "name": "1. Auth",
      "description": "Platform Admin login. Get a JWT to use for all subsequent requests.",
      "item": [
        {
          "name": "Login",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "if (pm.response.code === 200 || pm.response.code === 201) {",
                  "  const json = pm.response.json();",
                  "  pm.environment.set('pa_jwt_token', json.accessToken);",
                  "  pm.test('Login successful', () => pm.expect(json.accessToken).to.be.a('string'));",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"platformadmin@acme.com\",\n  \"password\": \"PlatformAdmin123!\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/auth/login",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "auth", "login"]
            },
            "description": "Login as Platform Admin. Saves JWT to pa_jwt_token environment variable. Use this token as Bearer auth for all other requests."
          },
          "response": []
        },
        {
          "name": "Get My Profile",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/platform-admin/auth/me",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "auth", "me"]
            },
            "description": "Get current Platform Admin user profile."
          },
          "response": []
        }
      ]
    },
    {
      "name": "2. Tenants",
      "description": "Create and manage tenants (companies) under your platform.",
      "item": [
        {
          "name": "List Tenants",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/platform-admin/tenants",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "tenants"]
            },
            "description": "List all tenants provisioned under this platform."
          },
          "response": []
        },
        {
          "name": "Create Tenant",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "if (pm.response.code === 201) {",
                  "  const json = pm.response.json();",
                  "  pm.environment.set('tenantId', json.id);",
                  "  pm.test('Tenant created', () => pm.expect(json.id).to.be.a('string'));",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"Acme Engineering\",\n  \"slug\": \"acme-engineering\",\n  \"adminEmail\": \"admin@acme-eng.com\",\n  \"adminName\": \"Tenant Admin\",\n  \"adminPassword\": \"TenantAdmin123!\",\n  \"settings\": {\n    \"autoApprovePlans\": false,\n    \"maxInterviewsPerMonth\": 100\n  }\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/platform-admin/tenants",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "tenants"]
            },
            "description": "Create a new tenant under this platform. Automatically creates a tenant admin user with the specified credentials."
          },
          "response": []
        },
        {
          "name": "Update Tenant",
          "request": {
            "method": "PUT",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"Acme Engineering (Updated)\",\n  \"settings\": {\n    \"autoApprovePlans\": true\n  }\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/platform-admin/tenants/{{tenantId}}",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "tenants", "{{tenantId}}"]
            }
          },
          "response": []
        },
        {
          "name": "Delete Tenant",
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/platform-admin/tenants/{{tenantId}}",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "tenants", "{{tenantId}}"]
            },
            "description": "Delete a tenant. This is irreversible."
          },
          "response": []
        }
      ]
    },
    {
      "name": "3. API Keys",
      "description": "Read-only view of API keys for this platform. API keys are issued and revoked by Teamcast Super Admin via POST /super-admin/platforms/:id/api-keys.",
      "item": [
        {
          "name": "List API Keys",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/platform-admin/api-keys",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "api-keys"]
            },
            "description": "List all API keys provisioned for this platform by Teamcast Super Admin. If a key was recently provisioned and not yet revealed, the raw key will appear here once."
          },
          "response": []
        }
      ]
    },
    {
      "name": "4. Users",
      "description": "Manage Platform Admin users (the people who log in to the Platform Admin portal).",
      "item": [
        {
          "name": "List Platform Users",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/platform-admin/users",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "users"]
            }
          },
          "response": []
        },
        {
          "name": "Create Platform User",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "if (pm.response.code === 201) {",
                  "  const json = pm.response.json();",
                  "  pm.environment.set('userId', json.id);",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"newadmin@acme.com\",\n  \"name\": \"New Platform User\",\n  \"password\": \"PlatformUser123!\",\n  \"role\": \"VIEWER\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/platform-admin/users",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "users"]
            },
            "description": "Create an additional Platform Admin user."
          },
          "response": []
        },
        {
          "name": "Get Platform User",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/platform-admin/users/{{userId}}",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "users", "{{userId}}"]
            }
          },
          "response": []
        },
        {
          "name": "Update Platform User",
          "request": {
            "method": "PUT",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"Updated Name\",\n  \"role\": \"ADMIN\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/platform-admin/users/{{userId}}",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "users", "{{userId}}"]
            }
          },
          "response": []
        },
        {
          "name": "Delete Platform User",
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/platform-admin/users/{{userId}}",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "users", "{{userId}}"]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "5. Stats",
      "item": [
        {
          "name": "Get Platform Statistics",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/platform-admin/stats",
              "host": ["{{baseUrl}}"],
              "path": ["platform-admin", "stats"]
            },
            "description": "Aggregate stats for this platform: total tenants, interviews, active users."
          },
          "response": []
        }
      ]
    },
    {
      "name": "6. Invitations",
      "description": "Invite users to a tenant via email. Platform Admins can invite tenant users only.",
      "item": [
        {
          "name": "Invite Tenant User",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"recruiter@tenant.com\",\n  \"firstName\": \"Priya\",\n  \"lastName\": \"Sharma\",\n  \"role\": \"RECRUITER\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/invitations/tenants/{{tenantId}}",
              "host": ["{{baseUrl}}"],
              "path": ["invitations", "tenants", "{{tenantId}}"]
            },
            "description": "Invite a user to a specific tenant. They receive an email with an account setup link.\n\nValid roles: ADMIN | RECRUITER | USER"
          },
          "response": []
        },
        {
          "name": "Get Invitation Details (public)",
          "request": {
            "auth": { "type": "noauth" },
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/invitations/{{invitationToken}}",
              "host": ["{{baseUrl}}"],
              "path": ["invitations", "{{invitationToken}}"]
            },
            "description": "Public endpoint. Returns invitation details for the accept-invitation page."
          },
          "response": []
        },
        {
          "name": "Accept Invitation (public)",
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"password\": \"SecurePassword123!\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/invitations/{{invitationToken}}/accept",
              "host": ["{{baseUrl}}"],
              "path": ["invitations", "{{invitationToken}}", "accept"]
            },
            "description": "Public endpoint. Invitee sets their password and activates the account."
          },
          "response": []
        }
      ]
    },
    {
      "name": "Health",
      "item": [
        {
          "name": "Liveness",
          "request": {
            "auth": { "type": "noauth" },
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/health/live",
              "host": ["{{baseUrl}}"],
              "path": ["health", "live"]
            }
          },
          "response": []
        },
        {
          "name": "Readiness",
          "request": {
            "auth": { "type": "noauth" },
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/health/ready",
              "host": ["{{baseUrl}}"],
              "path": ["health", "ready"]
            }
          },
          "response": []
        }
      ]
    }
  ]
}
