import { gql, actionPromise } from "./index";

export const gqlGetCommentLikesCount = (commentId) =>
  actionPromise(
    "getCommentLikesCount",
    gql(
      `query getCommentLikesCount($_id: String) {
        CommentFindOne(query: $_id) {
          likesCount
        }
      }`,
      {
        _id: JSON.stringify([{ _id: commentId }])
      }
    )
  );

  export const gqlAddLikeComment = (commentId) =>
  actionPromise(
    "addLikeComment",
    gql(
      `mutation AddLikeComment($like: LikeInput) {
          LikeUpsert(like: $like) {
            _id

          }
        }`,
      {
        like: {
          comment: {
            _id: commentId,
          },
        },
      }
    )
  );

  
  export const gqlDeleteLikeComment = (likeId, commentId) =>
  actionPromise(
    "deletePromise",
    gql(
      `mutation DeleteLikeComment($like:LikeInput){
          LikeDelete(like: $like)
          {
            _id
          }
        }`,
      {
        like: {
          _id: likeId,
          comment: {
            _id: commentId,
          },
        },
      }
    )
  );










  export const gqlAddCsdmmentLike = (commentId, like) =>
  actionPromise(
    "addCommentLike",
    gql(
      `mutation AddCommentLike($like: LikeInput){
          LikeUpsert(like: $like) {
            _id
          }
          CommentUpdate(_id: "${commentId}", like: $like) {
            _id
            text
            createdAt
            likesCount
            like {
              _id
            }
          }
        }`,
      {
        like: {
          user: {
            _id: like.userId,
          },
        },
      }
    )
  );



export const deleteCommentLike = (commentId) =>
  actionPromise(
    "deleteCommentLike",
    gql(
      `mutation DeleteCommentLike($like: CommentLikeInput!) {
        CommentLikeDelete(like: $like) {
          _id
          likes {
            user {
              _id
            }
          }
        }
      }`,
      {
        like: {
          comment: {
            _id: commentId,
          },
        },
      }
    )
  );