class ReleaseSerializer < Blueprinter::Base
  GO_ZERO_TIME   = "0001-01-01T00:00:00Z"
  TS_FORMAT      = "%Y-%m-%dT%H:%M:%S.%3NZ"
  FILE_PATH_FROM = "/softwares/"
  FILE_PATH_TO   = "/file/"

  field(:ID)             { |r| r.id }
  field(:CreatedAt)      { |r| r.created_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
  field(:UpdatedAt)      { |r| r.updated_at&.utc&.strftime(TS_FORMAT) || GO_ZERO_TIME }
  field(:DeletedAt)      { |r| r.deleted_at&.utc&.strftime(TS_FORMAT) }
  field(:softwareId)     { |r| r.software_id }
  field :version
  field(:cartridgePath)  { |r| r.cartridge_path.blank?  ? "" : r.cartridge_path.gsub(FILE_PATH_FROM, FILE_PATH_TO) }
  field(:sourcePath)     { |r| r.source_path.blank?     ? "" : r.source_path.gsub(FILE_PATH_FROM, FILE_PATH_TO) }
  field(:htmlFolderPath) { |r| r.html_folder_path.blank? ? "" : r.html_folder_path.gsub(FILE_PATH_FROM, FILE_PATH_TO) }
  field(:docsFolderPath) { |r| r.docs_folder_path.blank? ? "" : r.docs_folder_path.gsub(FILE_PATH_FROM, FILE_PATH_TO) }
end
