module BrandingAttachments
  extend ActiveSupport::Concern

  private

  def attach_branding_logo(record)
    file = params.dig(:branding, :logo_file)
    record.logo_file.attach(file) if file.present?
  end

  def normalize_hex_color(value, fallback)
    v = value.to_s.strip
    v = "##{v}" if v.match?(/\A[0-9A-Fa-f]{6}\z/)
    v.match?(Brandable::HEX_COLOR) ? v : fallback
  end
end
