---
openapi: "3.0.0"
info:
    version: "1.0.0"
    title: "Chill api"
    description: "Api documentation for chill. Currently, work in progress"
servers:
    -   url: "/api"
        description: "Your current dev server"

components:
    schemas:
        EntityWorkflowAttachment:
            type: object
            properties:
                id:
                    type: number
                    format: u64
                    minimum: 0
                relatedGenericDocKey:
                    type: string
                relatedGenericDocIdentifiers:
                    type: object
        AddAttachmentRequest:
            description: "A request to add attachment in an entity workflow"
            type: object
            properties:
                relatedGenericDocKey:
                    type: string
                relatedGenericDocIdentifiers:
                    type: object
        PaginatedResult:
            type: object
            properties:
                count:
                    type: number
                    format: u64
                pagination:
                    type: object
                    properties:
                        first:
                            type: number
                            format: u64
                            minimum: 0
                        items_per_page:
                            type: number
                            format: u64
                            minimum: 0
                        next:
                            type: string
                            nullable: true
                        previous:
                            type: string
                            nullable: true
                        more:
                            type: boolean
        Date:
            type: object
            properties:
                datetime:
                    type: string
                    format: date-time
        User:
            type: object
            properties:
                id:
                    type: integer
                type:
                    type: string
                    enum:
                        - user
                username:
                    type: string
                text:
                    type: string
        UserById:
            type: object
            properties:
                id:
                    type: integer
                type:
                    type: string
                    enum:
                        - user
        UserGroup:
            type: object
            properties:
                id:
                    type: integer
                type:
                    type: string
                    enum:
                        - user_group
                label:
                    type: object
                    additionalProperties: true
                backgroundColor:
                    type: string
                foregroundColor:
                    type: string
                exclusionKey:
                    type: string
        UserGroupById:
            type: object
            properties:
                id:
                    type: integer
                type:
                    type: string
                    enum:
                        - user_group
        Center:
            type: object
            properties:
                id:
                    type: integer
                name:
                    type: string
        Address:
            type: object
            properties:
                address_id:
                    type: integer
                text:
                    type: string
                postcode:
                    type: object
                    properties:
                        name:
                            type: string

        Country:
            type: object
            properties:
                id:
                    type: integer
                name:
                    type: object
                countryCode:
                    type: string

        PostalCode:
            type: object
            properties:
                id:
                    type: integer
                name:
                    type: string
                code:
                    type: string
                country:
                    type: object
                    properties:
                        id:
                            type: integer
                        name:
                            type: object
                        countryCode:
                            type: string

        AddressReference:
            type: object
            properties:
                id:
                    type: integer
                refId:
                    type: string
                street:
                    type: string
                streetNumber:
                    type: string
                postcode:
                    type: object
                    properties:
                        id:
                            type: integer
                        name:
                            type: string
                        code:
                            type: string
                        country:
                            type: object
                            properties:
                                id:
                                    type: integer
                                name:
                                    type: object
                                countryCode:
                                    type: string
                municipalityCode:
                    type: string
                source:
                    type: string
                point:
                    type: object
                    properties:
                        type:
                            type: string
                        coordinates:
                            type: array
                            items:
                                type: number
                            minItems: 2
                            maxItems: 2
        UserJob:
            type: object
            properties:
                id:
                    type: integer
                label:
                    type: object
                type:
                    type: string
        Workflow:
            type: object
            properties:
                id:
                    type: integer

        DashboardConfigItem:
            type: object
            properties:
                id:
                    type: integer
                type:
                    type: string
                metadata:
                    type: object
                userId:
                    type: integer
                position:
                    type: string

        NewsItem:
            type: object
            properties:
                id:
                    type: integer
                title:
                    type: string
                content:
                    type: string
                startDate:
                    $ref: "#/components/schemas/Date"
                endDate:
                    $ref: "#/components/schemas/Date"

paths:
    /1.0/search.json:
        get:
            summary: perform a search across multiple entities
            tags:
                - search
                - person
                - thirdparty
                - household
            description: >
                The search is performed across multiple entities. The entities must be listed into
                `type` parameters.

                The results are ordered by relevance, from the most to the lowest relevant.

            parameters:
                -   name: q
                    in: query
                    required: true
                    description: the pattern to search
                    schema:
                        type: string
                -   name: type[]
                    in: query
                    required: true
                    description: the type entities amongst the search is performed
                    schema:
                        type: array
                        items:
                            type: string
                            enum:
                                - person
                                - thirdparty
                                - user
                                - household
                                - user-group
            responses:
                200:
                    description: "OK"
    /1.0/main/address.json:
        post:
            tags:
                - address
            summary: create a new address
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                buildingName:
                                    type: string
                                corridor:
                                    type: string
                                distribution:
                                    type: string
                                extra:
                                    type: string
                                flat:
                                    type: string
                                floor:
                                    type: string
                                isNoAddress:
                                    type: boolean
                                point:
                                    type: array
                                    items:
                                        type: number
                                    minItems: 2
                                    maxItems: 2
                                postcode:
                                    $ref: '#/components/schemas/PostalCode'
                                steps:
                                    type: string
                                street:
                                    type: string
                                streetNumber:
                                    type: string
            responses:
                401:
                    description: "Unauthorized"
                404:
                    description: "Not found"
                200:
                    description: "OK"
                422:
                    description: "Unprocessable entity (validation errors)"
                400:
                    description: "transition cannot be applyed"
    /1.0/main/address/{id}.json:
        get:
            tags:
                - address
            summary: Return an address by id
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The address id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/Address"
                404:
                    description: "not found"
                401:
                    description: "Unauthorized"
        patch:
            tags:
                - address
            summary: patch an address
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The address id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                buildingName:
                                    type: string
                                corridor:
                                    type: string
                                distribution:
                                    type: string
                                extra:
                                    type: string
                                flat:
                                    type: string
                                floor:
                                    type: string
                                isNoAddress:
                                    type: boolean
                                point:
                                    type: array
                                    items:
                                        type: number
                                    minItems: 2
                                    maxItems: 2
                                postcode:
                                    $ref: "#/components/schemas/PostalCode"
                                steps:
                                    type: string
                                street:
                                    type: string
                                streetNumber:
                                    type: string
                                validFrom:
                                    type: string
                                validTo:
                                    type: string
            responses:
                401:
                    description: "Unauthorized"
                404:
                    description: "Not found"
                200:
                    description: "OK"
                422:
                    description: "Unprocessable entity (validation errors)"
                400:
                    description: "transition cannot be applyed"

    /1.0/main/address/{id}/duplicate.json:
        post:
            tags:
                - address
            summary: Duplicate an existing address
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The address id that will be duplicated
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/Address"
                404:
                    description: "not found"
                401:
                    description: "Unauthorized"

    /1.0/main/address-reference.json:
        get:
            tags:
                - address
            summary: Return a list of all reference addresses
            parameters:
                -   in: query
                    name: postal_code
                    required: false
                    schema:
                        type: integer
                    description: The id of a postal code to filter the reference addresses
            responses:
                200:
                    description: "ok"
    /1.0/main/address-reference/{id}.json:
        get:
            tags:
                - address
            summary: Return a reference address by id
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The reference address id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/AddressReference"
                404:
                    description: "not found"
                401:
                    description: "Unauthorized"

    /1.0/main/address-reference/by-postal-code/{id}/search.json:
        get:
            tags:
                - address
                - search
            summary: Return a reference address by id
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The reference address id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
                -   name: q
                    in: query
                    required: true
                    description: The search pattern
                    schema:
                        type: string
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/AddressReference"
                404:
                    description: "not found"
                401:
                    description: "Unauthorized"
                400:
                    description: "Bad request"
    /1.0/main/postal-code.json:
        get:
            tags:
                - address
            summary: Return a list of all postal-code
            parameters:
                -   in: query
                    name: country
                    required: false
                    schema:
                        type: integer
                    description: The id of a country to filter the postal code
            responses:
                200:
                    description: "ok"
        post:
            tags:
                - address
            summary: create a new PostalCode
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                name:
                                    type: string
                                code:
                                    type: string
                                country:
                                    $ref: "#/components/schemas/Country"
            responses:
                401:
                    description: "Unauthorized"
                404:
                    description: "Not found"
                200:
                    description: "OK"
                422:
                    description: "Unprocessable entity (validation errors)"
                400:
                    description: "transition cannot be applyed"

    /1.0/main/postal-code/{id}.json:
        get:
            tags:
                - address
            summary: Return a postal code by id
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The postal code id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/PostalCode"
                404:
                    description: "not found"
                401:
                    description: "Unauthorized"

    /1.0/main/postal-code/search.json:
        get:
            tags:
                - address
                - search
            summary: Search a postal code
            parameters:
                -   name: q
                    in: query
                    required: true
                    description: The search pattern
                    schema:
                        type: string
                -   name: country
                    in: query
                    required: false
                    description: The country id
                    schema:
                        type: integer
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/PostalCode"
                404:
                    description: "not found"
                400:
                    description: "Bad Request"

    /1.0/main/country.json:
        get:
            tags:
                - address
            summary: Return a list of all countries
            responses:
                200:
                    description: "ok"
    /1.0/main/country/{id}.json:
        get:
            tags:
                - address
            summary: Return a country by id
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The country id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/Country"
                404:
                    description: "not found"
                401:
                    description: "Unauthorized"

    /1.0/main/user.json:
        get:
            tags:
                - user
            summary: Return a list of all user
            responses:
                200:
                    description: "ok"
    /1.0/main/whoami.json:
        get:
            tags:
                - user
            summary: Return the currently authenticated user
            responses:
                200:
                    description: "ok"
    /1.0/main/user-current-location.json:
        get:
            tags:
                - user
            summary: Return the current location of the currently authenticated user
            responses:
                200:
                    description: "ok"
    /1.0/main/user/{id}.json:
        get:
            tags:
                - user
            summary: Return a user by id
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The user id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/User"
                404:
                    description: "not found"
                401:
                    description: "Unauthorized"

    /1.0/main/scope.json:
        get:
            tags:
                - scope
            summary: return a list of scopes
            responses:
                200:
                    description: "ok"
                401:
                    description: "Unauthorized"

    /1.0/main/scope/{id}.json:
        get:
            tags:
                - scope
            summary: return a list of scopes
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The scope id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                200:
                    description: "ok"
                401:
                    description: "Unauthorized"

    /1.0/main/location.json:
        get:
            tags:
                - location
            summary: Return a list of locations
            responses:
                200:
                    description: "ok"
                401:
                    description: "Unauthorized"
        post:
            tags:
                - location
            summary: create a new location
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                type:
                                    type: string
                                name:
                                    type: string
                                phonenumber1:
                                    type: string
                                phonenumber2:
                                    type: string
                                email:
                                    type: string
                                address:
                                    type: object
                                    properties:
                                        id:
                                            type: integer
                                locationType:
                                    type: object
                                    properties:
                                        id:
                                            type: integer
                                        type:
                                            type: string
            responses:
                401:
                    description: "Unauthorized"
                404:
                    description: "Not found"
                200:
                    description: "OK"
                422:
                    description: "Unprocessable entity (validation errors)"
                400:
                    description: "transition cannot be applyed"

    /1.0/main/location/{id}.json:
        get:
            tags:
                - location
            summary: Return the given location
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The location id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                200:
                    description: "ok"
                401:
                    description: "Unauthorized"

    /1.0/main/location-type.json:
        get:
            tags:
                - location
            summary: Return a list of location types
            responses:
                200:
                    description: "ok"
                401:
                    description: "Unauthorized"

    /1.0/main/permissions/info.json:
        post:
            tags:
                - permissions
            summary: Return info about permissions on entity
            responses:
                200:
                    description: "ok"
                401:
                    description: "Unauthorized"
                400:
                    description: "Bad request"
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                object:
                                    type: object
                                class:
                                    type: string
                                roles:
                                    type: array
                                    items:
                                        type: string
                        examples:
                            an-accompanying-period:
                                value:
                                    object:
                                        type: accompanying_period
                                        id: 1
                                    class: 'Chill\PersonBundle\Entity\AccompanyingPeriod'
                                    roles:
                                        - "CHILL_PERSON_ACCOMPANYING_PERIOD_SEE"
    /1.0/main/notification/{id}/mark/read:
        post:
            tags:
                - notification
            summary: mark a notification as read
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The notification id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                202:
                    description: "accepted"
                403:
                    description: "unauthorized"
    /1.0/main/notification/{id}/mark/unread:
        post:
            tags:
                - notification
            summary: mark a notification as unread
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The notification id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                202:
                    description: "accepted"
                403:
                    description: "unauthorized"
    /1.0/main/notification/mark/allread:
        post:
            tags:
                - notification
            summary: Mark all notifications as read
            responses:
                202:
                    description: "accepted"
                403:
                    description: "unauthorized"
    /1.0/main/notification/mark/undoallread:
        post: # Use POST method for creating resources
            tags:
                - notification
            summary: Mark notifications as unread
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                ids:
                                    type: array
                                    items:
                                        type: integer
                                        example: [ 1, 2, 3 ] # Example array of IDs
            responses:
                "202":
                    description: Notifications marked as unread successfully
                "403":
                    description: Unauthorized
    /1.0/main/civility.json:
        get:
            tags:
                - civility
            summary: Return all civility types
            responses:
                200:
                    description: "ok"
                401:
                    description: "Unauthorized"
    /1.0/main/gender.json:
        get:
            tags:
                - gender
            summary: Return all gender types
            responses:
                200:
                    description: "ok"
                401:
                    description: "Unauthorized"
    /1.0/main/user-job.json:
        get:
            tags:
                - user
            summary: Return a list of all user jobs
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/UserJob"
    /1.0/main/workflow/my:
        get:
            tags:
                - workflow
            summary: Return a list of workflows awaiting for user's action
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                type: array
                                items:
                                    $ref: "#/components/schemas/Workflow"
                403:
                    description: "Unauthorized"
    /1.0/main/workflow/my-cc:
        get:
            tags:
                - workflow
            summary: Return a list of workflows for which user was notified in Cc
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                type: array
                                items:
                                    $ref: "#/components/schemas/Workflow"
                403:
                    description: "Unauthorized"
    /1.0/main/dashboard-config-item.json:
        get:
            tags:
                - dashboard config item
            summary: Returns the dashboard configuration for the current user.
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/DashboardConfigItem"
                403:
                    description: "Unauthorized"

    /1.0/main/news/current.json:
        get:
            tags:
                - news items
            summary: Returns a list of news items which are valid
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                type: array
                                items:
                                    $ref: '#/components/schemas/NewsItem'
                403:
                    description: "Unauthorized"
    /1.0/main/user-group.json:
        get:
            tags:
                - user-group
            summary: Return a list of users-groups
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                type: array
                                items:
                                    $ref: '#/components/schemas/UserGroup'
                403:
                    description: "Unauthorized"
    /1.0/main/workflow/{id}/attachment:
        get:
            tags:
                - workflow
            summary: Get a list of attachements for a given workflow
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The entity workflow id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                type: array
                                items:
                                    $ref: '#/components/schemas/EntityWorkflowAttachment'
        post:
            tags:
                - workflow
            summary: Create a new attachment
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The entity workflow id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/AddAttachmentRequest'
            responses:
                200:
                    description: "ok"
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/EntityWorkflowAttachment'
    /1.0/main/workflow/attachment/{id}:
        delete:
            tags:
                - workflow
            summary: Remove an attachment
            parameters:
                -   name: id
                    in: path
                    required: true
                    description: The entity workflow 's attachment id
                    schema:
                        type: integer
                        format: integer
                        minimum: 1
            responses:
                204:
                    description: "resource was deleted successfully"

