# Skeleton contract for the Majlis API. Status: draft, not authoritative yet.
# Context: docs/06-technical-specifications/api.md
openapi: 3.1.0
info:
  title: Majlis API
  version: 0.3.0
  description: Draft contract. Endpoint register and rules live in api.md.
servers:
  - url: https://api.example.invalid
    description: Placeholder
tags:
  - { name: membership }
  - { name: places }
  - { name: events }
  - { name: joins }
  - { name: ask }
paths:
  /account:
    get:
      tags: [membership]
      summary: Signed-in member profile (email never returned)
      operationId: getAccount
      responses:
        "200": { description: Member profile }
        "401": { description: Not authenticated }
  /pilot-application:
    post:
      tags: [membership]
      summary: Submit a pilot application
      operationId: createPilotApplication
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [display_name, gender, city_id]
              properties:
                display_name: { type: string, maxLength: 50 }
                gender: { type: string, enum: [male, female] }
                city_id: { type: string, format: uuid }
      responses:
        "201": { description: Application created (pending) }
        "409": { description: Active application exists }
        "422": { description: Validation failed }
  /places:
    get:
      tags: [places]
      summary: List places (type + amenity filters)
      operationId: listPlaces
      parameters:
        - { name: type, in: query, schema: { type: string, enum: [mosque, cafe, restaurant, other] } }
        - { name: lat, in: query, schema: { type: number } }
        - { name: lng, in: query, schema: { type: number } }
        - { name: amenities, in: query, schema: { type: string } }
        - { name: cursor, in: query, schema: { type: string } }
      responses:
        "200": { description: Place list }
  /places/{id}:
    get:
      tags: [places]
      summary: Place detail (mosque includes prayer times and join state)
      operationId: getPlace
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: Place detail }
        "404": { description: Not found }
  /events:
    get:
      tags: [events]
      summary: List events visible to caller (gender wall applied server-side)
      operationId: listEvents
      responses:
        "200": { description: Event list without cross-gender items }
    post:
      tags: [events]
      summary: Create event (gender_type stamped server-side)
      operationId: createEvent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [place_id, title, start_at, category, capacity, language]
              properties:
                place_id: { type: string, format: uuid }
                title: { type: string }
                start_at: { type: string, format: date-time }
                category: { type: string, enum: [religious, social, cultural] }
                capacity: { type: integer, minimum: 1 }
                language: { type: string }
                price_info: { type: string }
      responses:
        "201": { description: Event created }
        "422": { description: Validation failed }
  /events/{id}/join:
    post:
      tags: [events]
      summary: Join event (atomic capacity check)
      operationId: joinEvent
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: Joined }
        "409": { description: Full or gender wall }
    delete:
      tags: [events]
      summary: Withdraw before start
      operationId: withdrawEvent
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: Withdrawn }
        "409": { description: Already started }
  /mosques/{id}/joins:
    post:
      tags: [joins]
      summary: Mark "I'm going" for a prayer
      operationId: joinPrayer
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [prayer, prayer_date]
              properties:
                prayer: { type: string, enum: [fajr, dhuhr, asr, maghrib, isha] }
                prayer_date: { type: string, format: date }
      responses:
        "201": { description: Marked, returns count }
        "409": { description: Window closed }
  /questions:
    get:
      tags: [ask]
      summary: List questions for a channel
      operationId: listQuestions
      responses:
        "200": { description: Question list }
    post:
      tags: [ask]
      summary: Create question
      operationId: createQuestion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [channel, title, body]
              properties:
                channel: { type: string, enum: [community, diyanet] }
                category: { type: string }
                title: { type: string }
                body: { type: string }
                visibility: { type: string, enum: [public, private], default: public }
                anonymous_publish_allowed: { type: boolean, default: false }
      responses:
        "201": { description: Created (pending moderation) }
        "422": { description: Validation failed }
components:
  securitySchemes:
    sessionCookie:
      type: apiKey
      in: cookie
      name: majlis_session
security:
  - sessionCookie: []
