# frozen_string_literal: true

module Types
  module WorkItems
    class NegatedWorkItemFilterInputType < BaseInputObject
      graphql_name 'NegatedWorkItemFilterInput'

      argument :assignee_usernames, [GraphQL::Types::String],
        required: false,
        validates: { length: { maximum: ::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT } },
        description: "Usernames of users not assigned to the work item " \
          "(maximum is #{::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT} usernames)."
      argument :author_username, [GraphQL::Types::String],
        required: false,
        validates: { length: { maximum: ::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT } },
        description: "Username of a user who didn't author the work item " \
          "(maximum is #{::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT} usernames)."
      argument :label_name, [GraphQL::Types::String],
        required: false,
        validates: { length: { maximum: ::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT } },
        description: "Labels not applied to the work item " \
          "(maximum is #{::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT} labels)."
      argument :milestone_title, [GraphQL::Types::String],
        required: false,
        validates: { length: { maximum: ::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT } },
        description: "Milestone not applied to the work item " \
          "(maximum is #{::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT} milestones)."
      argument :milestone_wildcard_id, ::Types::NegatedMilestoneWildcardIdEnum,
        required: false,
        description: 'Filter by negated milestone wildcard values.'
      argument :my_reaction_emoji, GraphQL::Types::String,
        required: false,
        description: 'Filter by reaction emoji not applied by the current user.'
      argument :parent_ids, [::Types::GlobalIDType[::WorkItem]],
        description: "Filter work items by global IDs who don't belong to parent items " \
          "(maximum is #{::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT} IDs).",
        required: false,
        validates: { length: { maximum: ::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT } },
        experiment: { milestone: '18.3' },
        prepare: ->(global_ids, _ctx) { GitlabSchema.parse_gids(global_ids, expected_type: ::WorkItem).map(&:model_id) }
      argument :release_tag, [GraphQL::Types::String],
        required: false,
        validates: { length: { maximum: ::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT } },
        description: "Release tag not associated with the work items's milestone " \
          "(maximum is #{::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT} tags). Ignored when parent is a group ."
      argument :types, [::Types::IssueTypeEnum], as: :issue_types,
        description: 'Filter out work items by the given types.',
        required: false
      argument :work_item_type_ids,
        [::Types::GlobalIDType[::WorkItems::Type]],
        required: false,
        validates: { length: { maximum: ::WorkItems::SharedFilterArguments::MAX_FIELD_LIMIT } },
        description: 'Filter out work items by work item type global IDs.',
        prepare: ->(global_ids, _ctx) { global_ids.map(&:model_id) }

      validates mutually_exclusive: [:issue_types, :work_item_type_ids]
      validates mutually_exclusive: [:milestone_title, :milestone_wildcard_id]
    end
  end
end

Types::WorkItems::NegatedWorkItemFilterInputType.prepend_mod_with('Types::WorkItems::NegatedWorkItemFilterInputType')
