---
get:
  summary: View User Group Contact Details

  tags:
    - User Group

  description: |
    > Example of a User Group Contact Details without inheritable previews:

    ```json
    {
      "inherited_from": "1",
      "address": {
        "company_number": "5568166804",
        "company_name": "Scrive",
        "address": "Grev Turegatan 11A",
        "zip": "114 46",
        "city": "Stockholm",
        "country": "Sweden"
      }
    }
    ```

    > Example of a User Group Contact Details with inheritable previews
    > (where the User Group is root and therefore must have its own Contact
    > Details object):

    ```json
    {
      "inherited_from": null,
      "address": {
        "company_number": "0987654321",
        "company_name": "Scrive",
        "address": "Other Street",
        "zip": "00-321",
        "city": "Warsaw",
        "country": "PL"
      },
      "inheritable_preview": null
    }
    ```

    > Example of a User Group Contact Details with inheritable previews
    > (where the User Group is a child with its own Contact Details object):

    ```json
    {
      "inherited_from": null,
      "address": {
        "company_number": "0987654321",
        "company_name": "Scrive",
        "address": "123 Other Street",
        "zip": "00-321",
        "city": "Warsaw",
        "country": "Poland"
      },
      "inheritable_preview": {
        "inherited_from": "1",
        "address": {
          "company_number": "5568166804",
          "company_name": "Scrive",
          "address": "Grev Turegatan 11A",
          "zip": "114 46",
          "city": "Stockholm",
          "country": "Sweden"
        }
      }
    }
    ```

    > Example of a User Group Contact Details with inheritable previews
    > (where the User Group is a child which inherits, meaning that the
    > `inheritable_preview` field is a duplicate):

    ```json
    {
      "inherited_from": "1",
      "address": {
        "company_number": "5568166804",
        "company_name": "Scrive",
        "address": "Grev Turegatan 11A",
        "zip": "114 46",
        "city": "Stockholm",
        "country": "Sweden"
      },
      "inheritable_preview": {
        "inherited_from": "1",
        "address": {
          "company_number": "5568166804",
          "company_name": "Scrive",
          "address": "Grev Turegatan 11A",
          "zip": "114 46",
          "city": "Stockholm",
          "country": "Sweden"
        }
      }
    }
    ```

    This endpoint is used to get an overview of a given User Group's
    `contact_details` object.

    The `contact_details` object can be inherited. In this case, the
    `inherited_from` field will be non-null. The value in this field is the ID
    of the User Group which the value is inherited from.

    Inheritance works as follows:

    Root User Groups (i.e. those who are not children of other User Groups) may
    not inherit since there are no ancestors to inherit from.

    A child User Group may inherit or have its own dedicated object. In the case
    that a User Group chooses to inherit the `contact_details` object, then that
    User Group will inherit from the closest direct ancestor with its own
    `contact_details` object. Since root User Groups cannot inherit, there will
    always be an ancestor from which a child can inherit.

    If you would like to see what a User Group _would_ inherit then you can
    append `?include-inheritable` to the URL when making the call. This will add
    extra `inheritable_preview` subtrees to the objects which perform the
    inheritance calculation, ignoring whether or not the User Group already
    inherits.

  parameters:
    - name: user_group_id
      in: path
      type: integer
      description: |
        The ID of the User Group whose `contact_details` object you wish to view
      required: true
    - name: include-inheritable
      in: query
      type: boolean
      description: |
        Append `?include-inheritable` to the URL to see a preview of which
        values can be inherited from an ancestor User Group.
      required: false

  responses:
    200:
      $ref: ../../scrive_api.yaml#/definitions/UserGroupContactDetails
    403:
      description: |
        Insufficient Permissions error (this means that either no User Group
        exists with this ID or that you do not have permission to view it)
