resources:
  App\Entity\Advert\Advert:
    operations:
      ApiPlatform\Metadata\GetCollection:
        filters: [ 'advert.order_filter', 'advert.search_filter', 'advert.global_search_filter', 'advert.exist_filter', 'advert.boolean_filter', 'advert.published_filter', 'advert.owner_search_filter' ]
        security: 'is_granted("ROLE_ADMIN")'
        openapiContext:
          summary: Advert - List.
          description: >
            Retrieves a list of Advert
        normalizationContext:
          groups:
            - 'identifier:read'
            - 'time_trace:read'
            - 'activity_area:read'
            - 'advert:read'
            - 'customer:read_essential'
            - 'user:read_essential'
            - 'media_file:read'

      get_mine:
        class: ApiPlatform\Metadata\GetCollection
        security: 'is_granted("ROLE_CUSTOMER")'
        filters: [ 'advert.order_filter', 'advert.search_filter', 'advert.global_search_filter', 'advert.exist_filter', 'advert.boolean_filter', 'advert.published_filter' ]
        method: GET
        uriTemplate: /adverts/mine
        openapiContext:
          summary: Advert - List of mine.
          description: >
            Retrieves a list of Advert who is mine
        normalizationContext:
          groups:
            - 'identifier:read'
            - 'time_trace:read'
            - 'time_trace:read'
            - 'activity_area:read'
            - 'advert:read'
            - 'customer:read_essential'
            - 'user:read_essential'
            - 'media_file:read'

      get_published:
        class: ApiPlatform\Metadata\GetCollection
        filters: [ 'advert.order_filter', 'advert.search_filter', 'advert.global_search_filter', 'advert.exist_filter', 'advert.boolean_filter', 'advert.published_filter' ]
        security: 'is_granted("ROLE_USER")'
        method: GET
        uriTemplate: /adverts/published
        openapiContext:
          summary: Advert - List of published advert.
          description: >
            Retrieves a list of Advert who is published
        normalizationContext:
          groups:
            - 'identifier:read'
            - 'time_trace:read'
            - 'activity_area:read'
            - 'advert:read'
            - 'customer:read_essential'
            - 'user:read_essential'
            - 'media_file:read'

      ApiPlatform\Metadata\Get:
        security: 'is_granted("GET_ITEM", object)'
        openapiContext:
          summary: Advert - Item.
          description: >
            Retrieves a item of Advert
        normalizationContext:
          groups:
            - 'identifier:read'
            - 'time_trace:read'
            - 'activity_area:read'
            - 'time_trace:read'
            - 'advert:read'
            - 'customer:read_essential'
            - 'user:read_essential'
            - 'media_file:read'

      ApiPlatform\Metadata\Post:
        security: 'is_granted("ROLE_CUSTOMER")'
        inputFormats:
          json: [ 'application/json' ]
          multipart: [ 'multipart/form-data' ]
        openapiContext:
          summary: Advert - Create.
          description: >
            create an item of Advert
        normalizationContext:
          groups:
            - 'identifier:read'
            - 'time_trace:read'
            - 'activity_area:read'
            - 'media_file:read'
            - 'time_trace:read'
            - 'customer:read_essential'
            - 'user:read_essential'
            - 'advert:read'
        denormalizationContext:
          groups:
            - 'advert:write'
            - 'media_file:write'

      ApiPlatform\Metadata\Put:
        inputFormats:
          json: [ 'application/json' ]
          multipart: [ 'multipart/form-data' ]
        securityPostDenormalize: "is_granted('ROLE_ADMIN') or (object.owner == user and previous_object.owner == user)"
        openapiContext:
          summary: Advert - Update.
          description: >
            update an item of Advert
        normalizationContext:
          groups:
            - 'identifier:read'
            - 'time_trace:read'
            - 'activity_area:read_essential'
            - 'media_file:read'
            - 'advert:read'
            - 'customer:read_essential'
            - 'user:read_essential'
        denormalizationContext:
          groups:
            - 'advert:write'
            - 'media_file:write'

      ApiPlatform\Metadata\Delete:
        processor: App\State\AdvertDeletionProcessor
        security: 'is_granted("ROLE_CUSTOMER")'
        openapiContext:
          summary: Advert - Delete.
          description: >
            delete an item of Advert
