package com.google.gerrit.server.restapi.change;

import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.change.DraftCommentResource;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;

@Singleton
public class GetDraftComment implements RestReadView<DraftCommentResource> {

  private final Provider<CommentJson> commentJson;

  @Inject
  GetDraftComment(Provider<CommentJson> commentJson) {
    this.commentJson = commentJson;
  }

  @Override
  public Response<CommentInfo> apply(DraftCommentResource rsrc) throws PermissionBackendException {
    return Response.ok(commentJson.get().newHumanCommentFormatter().format(rsrc.getComment()));
  }
}
