class Fee::MiscFeeType < Fee::BaseFeeType
  AGFS_SUPPLEMENTARY_ONLY_TYPES = %w[MISAF MIPCM].freeze
  AGFS_SUPPLEMENTARY_SHARED_TYPES = %w[MISAU MISPF MIWPF MIDTH MIDTW MIDHU MIDWU
                                       MIDSE MIDSU MIPHC MISHR MISHU MIUMU MIUMO].freeze
  AGFS_SUPPLEMENTARY_TYPES = (AGFS_SUPPLEMENTARY_ONLY_TYPES + AGFS_SUPPLEMENTARY_SHARED_TYPES).freeze
  TRIAL_ONLY_TYPES = %w[MIUMU MIUMO].freeze

  default_scope { order(description: :asc) }

  scope :without_supplementary_only, -> { where.not(unique_code: AGFS_SUPPLEMENTARY_ONLY_TYPES) }
  scope :supplementary, -> { where(unique_code: AGFS_SUPPLEMENTARY_TYPES) }
  scope :without_trial_fee_only, -> { where.not(unique_code: TRIAL_ONLY_TYPES) }

  def fee_category_name
    'Miscellaneous Fees'
  end
end

class Fee::MiscFeeType < Fee::BaseFeeType
  AGFS_SUPPLEMENTARY_ONLY_TYPES = %w[MISAF MIPCM].freeze
  AGFS_SUPPLEMENTARY_SHARED_TYPES = %w[MISAU MISPF MIWPF MIDTH MIDTW MIDHU MIDWU
                                       MIDSE MIDSU MIPHC MISHR MISHU MIUMU MIUMO].freeze
  AGFS_SUPPLEMENTARY_TYPES = (AGFS_SUPPLEMENTARY_ONLY_TYPES + AGFS_SUPPLEMENTARY_SHARED_TYPES).freeze
  TRIAL_ONLY_TYPES = %w[MIUMU MIUMO].freeze

  # default_scope { order(description: :asc) }
  default_scope { order(Arel.sql("regexp_replace(\"fee_types\".\"description\", '[()]', '', 'g')")) }

  scope :without_supplementary_only, -> { where.not(unique_code: AGFS_SUPPLEMENTARY_ONLY_TYPES) }
  scope :supplementary, -> { where(unique_code: AGFS_SUPPLEMENTARY_TYPES) }
  scope :without_trial_fee_only, -> { where.not(unique_code: TRIAL_ONLY_TYPES) }

  def fee_category_name
    'Miscellaneous Fees'
  end
end

Enforce consistent ordering of strings across postgres distibutions
Enforce consistent ordering of strings across postgres distibutions

Differences in postgres distributions and hosts OS appear to cause
different handling of braces when ordering by strings. For example
postgres 9.6 on alpine and postgres 9.6 on darwin/apple order strings
containing braces consistently but differently from debian and Amazon
linux hosted versions.

```on darwin and alpine
Confiscation hearings (half day uplift)
Confiscation hearings (half day)
```

```on debian and amazon linux
Confiscation hearings (half day)
Confiscation hearings (half day uplift)
```
