<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    xmlns:i18n="http://namespaces.zope.org/i18n"
    xmlns:monkey="http://namespaces.plone.org/monkey"
    i18n_domain="senaite.core">

    <!-- Dynamic Results Range Adapter
         Looked up in `abstractroutineanalysis.getResultsRange` -->
    <adapter
      for="bika.lims.interfaces.IRoutineAnalysis"
      factory=".dynamicresultsrange.DynamicResultsRange"
      provides="bika.lims.interfaces.IDynamicResultsRange"
      />

    <adapter
      for="zope.interface.Interface
           zope.publisher.interfaces.browser.IBrowserRequest"
      factory="bika.lims.adapters.referencewidgetvocabulary.DefaultReferenceWidgetVocabulary"
      provides="bika.lims.interfaces.IReferenceWidgetVocabulary"
    />

    <!-- ClientAwareReferenceWidgetVocabulary
    Injects getClientUID or getParentUID as additional search criteria for
    client-bound reference fields -->
    <adapter
      for="bika.lims.interfaces.IBatch
           zope.publisher.interfaces.browser.IBrowserRequest"
      factory=".referencewidgetvocabulary.ClientAwareReferenceWidgetVocabulary"
      provides="bika.lims.interfaces.IReferenceWidgetVocabulary" />
    <adapter
      for="bika.lims.interfaces.IClient
           zope.publisher.interfaces.browser.IBrowserRequest"
      factory=".referencewidgetvocabulary.ClientAwareReferenceWidgetVocabulary"
      provides="bika.lims.interfaces.IReferenceWidgetVocabulary" />
    <adapter
      for="bika.lims.interfaces.IAnalysisRequest
           zope.publisher.interfaces.browser.IBrowserRequest"
      factory=".referencewidgetvocabulary.ClientAwareReferenceWidgetVocabulary"
      provides="bika.lims.interfaces.IReferenceWidgetVocabulary" />


    <!--
    FIELDS/WIDGETS VISIBILITY
    ·························
    These adapters allow to set more fine-grained criteria to modify fields
    visibility after their visibility for a given mode is granted by workflow
    permissions. E.g., in some cases we want a field to be displayed only if a
    given setting from setup is enabled, or make editable a field when other
    field has value, etc. These are use cases that cannot be modeled by using
    the workflow field-specific permissions only, rather specific adapters.

    Important:
    If you only want a field to be visible/invisible depending on the context
    status, add the permission in the proper workflow instead of adding
    an adapter.

    -->
    <!-- Hide all those fields from Analysis Request that have been declared as
    hidden in bika.lims.hiddenattributes registry key -->
    <adapter
      factory=".widgetvisibility.RegistryHiddenFieldsVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequest"
      name="RegistryHiddenFieldsVisibility"
    />

    <!-- Display/Hide accountancy-related fields (e.g. price, discount, etc.)
    based on system settings (setup's "Show Prices" option) -->
    <adapter
      factory=".widgetvisibility.AccountancyFieldsVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IClient"
      name="AccountancyFieldsVisibility"
    />

    <!-- Display/Hide accountancy-related fields (e.g. price, discount, etc.)
    based on system settings (setup's "Show Prices" option) -->
    <adapter
      factory=".widgetvisibility.AccountancyFieldsVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequest"
      name="AccountancyFieldsVisibility"
    />

    <!-- Display/Hide Batch field in AR Add form when creation takes place
    inside a Batch context. -->
    <adapter
      factory=".widgetvisibility.BatchFieldVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequest"
      name="BatchFieldVisibility"
    />

    <!-- Hides the client field in AR Add form when the creation takes place
    inside a Client context. Makes the field readonly in mode=edit -->
    <adapter
      factory=".widgetvisibility.ClientFieldVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequest"
      name="ClientFieldVisibility"
    />

    <!-- Display Analysis Request's Date Received field in edit mode only if the
    Analysis Request is in an "open" state (all analyses it contains are either
    in "unassigned" or "assigned" status). Otherwise, display as read-only -->
    <adapter
        factory=".widgetvisibility.DateReceivedFieldVisibility"
        provides="bika.lims.interfaces.IATWidgetVisibility"
        for="bika.lims.interfaces.IAnalysisRequest"
        name="DateReceivedFieldVisibility"
    />

    <!-- Hide/Display the fields related with Sampling Workflow (e.g. Sampler,
    Date Sampled, Sampling Date, etc.) -->
    <adapter
      factory=".widgetvisibility.SamplingFieldsVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequest"
      name="SamplingFieldsVisibility"
    />

    <!-- Hide/Display the fields related with Scheduled Sampling Workflow (e.g.
    Scheduled Sampler, etc.) -->
    <adapter
      factory=".widgetvisibility.ScheduledSamplingFieldsVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequest"
      name="ScheduledSamplingFieldsVisibility"
    />

    <!-- Hide/Display the fields related with Preservation Workflow (e.g.
    Preservation, DatePreserved, etc.) -->
    <adapter
      factory=".widgetvisibility.PreservationFieldsVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequest"
      name="PreservationFieldsVisibility"
    />

    <!-- DateSampled cannot be edited in Secondary Analysis Requests -->
    <adapter
      factory=".widgetvisibility.SecondaryDateSampledFieldVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequestSecondary"
      name="SecondaryDateSampledFieldVisibility"
    />

    <!-- Hide/Display the InternalUse field to Client contact users -->
    <adapter
      factory=".widgetvisibility.InternalUseFieldVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequest"
      name="InternalUseFieldVisibility"
    />

    <!-- Hide/Display PrimarySample field. Always hidden for non-secondary ARs,
    otherwise readonly mode -->
    <adapter
      factory=".widgetvisibility.PrimaryAnalysisRequestFieldVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IAnalysisRequest"
      name="PrimaryAnalysisRequestFieldVisibility"
    />

    <!-- Batch: Hide Client field if the batch is assigned to a Client or the
    batch contains samples from different clients -->
    <adapter
      factory=".widgetvisibility.BatchClientFieldVisibility"
      provides="bika.lims.interfaces.IATWidgetVisibility"
      for="bika.lims.interfaces.IBatch"
      name="BatchClientFieldVisibility"
    />
    <!---
    END OF FIELDS/WIDGETS VISIBILITY
    -->

    <!-- Stickers -->
    <!-- IGetStickerTemplates adapters -->
    <adapter
      factory="bika.lims.adapters.stickers.GetSampleStickers"
      for="bika.lims.interfaces.IAnalysisRequest"
      provides="bika.lims.interfaces.IGetStickerTemplates"
    />

</configure>
