class SoftwareSerializer < Blueprinter::Base
  GO_ZERO_TIME = "0001-01-01T00:00:00Z"
  TS_FORMAT    = "%Y-%m-%dT%H:%M:%S.%3NZ"

  field(:ID)           { |sw| sw.id }
  field(:CreatedAt)    { |sw| sw.created_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
  field(:UpdatedAt)    { |sw| sw.updated_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
  field(:DeletedAt)    { |sw| sw.deleted_at&.utc&.strftime(TS_FORMAT) }
  field :name
  field :title
  field :author
  field(:desc)         { |sw| sw.desc.to_s }
  field(:story)        { |sw| sw.story.to_s }
  field(:license)      { |sw| sw.license.to_s }
  field :platform
  field :status
  field(:highlighted)  { |sw| sw.highlighted ? true : false }
  field(:externalLinks) { |sw| ExternalLinkSerializer.render_as_hash(sw.external_links) }
  field(:imageUrl)     { |sw| sw.image_id ? "/api/image/#{sw.image_id}" : nil }
end
