/api/location:
  get:
    tags: [Location]
    summary: List locations
    security:
      - bearerAuth: []
    parameters:
      - name: LocCode
        in: query
        schema:
          type: string
        description: Filter by location code
      - name: LocName
        in: query
        schema:
          type: string
        description: Filter by location name (searches in LocFull)
    responses:
      '200':
        description: List of locations
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                message:
                  type: string
                data:
                  type: array
                  items:
                    $ref: '../components/schemas/master-data.yaml#/Location'

  post:
    tags: [Location]
    summary: Create location
    security:
      - bearerAuth: []
    requestBody:
      required: true
      content:
        application/json:
          schema:
            type: object
            required:
              - LocCode
              - LocFull
            properties:
              SiteID:
                type: integer
                description: Reference to site
              LocCode:
                type: string
                maxLength: 6
                description: Location code (short identifier)
              Parent:
                type: integer
                nullable: true
                description: Parent location ID for hierarchical locations
              LocFull:
                type: string
                maxLength: 255
                description: Full location name
              Description:
                type: string
                maxLength: 255
                description: Location description
              LocType:
                type: string
                description: Location type code (e.g., ROOM, WARD, BUILDING)
    responses:
      '201':
        description: Location created successfully
        content:
          application/json:
            schema:
              $ref: '../components/schemas/common.yaml#/SuccessResponse'
      '422':
        description: Validation error
        content:
          application/json:
            schema:
              $ref: '../components/schemas/common.yaml#/ErrorResponse'


  delete:
    tags: [Location]
    summary: Delete location
    security:
      - bearerAuth: []
    requestBody:
      required: true
      content:
        application/json:
          schema:
            type: object
            required:
              - LocationID
            properties:
              LocationID:
                type: integer
                description: Location ID to delete
    responses:
      '200':
        description: Location deleted successfully
        content:
          application/json:
            schema:
              $ref: '../components/schemas/common.yaml#/SuccessResponse'

/api/location/{id}:
  get:
    tags: [Location]
    summary: Get location by ID
    security:
      - bearerAuth: []
    parameters:
      - name: id
        in: path
        required: true
        schema:
          type: integer
        description: Location ID
    responses:
      '200':
        description: Location details
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                message:
                  type: string
                data:
                  $ref: '../components/schemas/master-data.yaml#/Location'

  patch:
    tags: [Location]
    summary: Update location
    security:
      - bearerAuth: []
    parameters:
      - name: id
        in: path
        required: true
        schema:
          type: integer
        description: Location ID to update
    requestBody:
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              SiteID:
                type: integer
                description: Reference to site
              LocCode:
                type: string
                maxLength: 6
                description: Location code (short identifier)
              Parent:
                type: integer
                nullable: true
                description: Parent location ID for hierarchical locations
              LocFull:
                type: string
                maxLength: 255
                description: Full location name
              Description:
                type: string
                maxLength: 255
                description: Location description
              LocType:
                type: string
                description: Location type code (e.g., ROOM, WARD, BUILDING)
    responses:
      '201':
        description: Location updated successfully
        content:
          application/json:
            schema:
              $ref: '../components/schemas/common.yaml#/SuccessResponse'
      '422':
        description: Validation error
        content:
          application/json:
            schema:
              $ref: '../components/schemas/common.yaml#/ErrorResponse'
