class Page
  include Cmtool::Includes::Page
  include ActiveModel::SerializerSupport
  def self.layouts
    %w[theme1 theme1-home theme1-with-subnavigation]
  end

  def self.suppliers_page(name, locale: :en)
    find_by_name_and_locale("suppliers-#{name}", locale) || NullPage.new(name, locale: locale)
  end

  class NullPage < NullModel
    attr_reader :name, :locale, :title, :body
    def initialize(name, locale: 'en')
      @name = name
      @locale = locale
      @body = ::I18n.t('page.not_found', locale: locale)
    end

    def title
      @title ||= name.to_s.humanize.gsub(/\W/, ' ')
    end
  end
end
