import { getDatetime } from "taehui-ts/date";

import DB from "src/system/DB";
import { Commentary } from "src/Commentry";

export const getCommentary = async (): Promise<Commentary[]> => {
  return DB.getCommentary();
};

export const postCommentary = async (
  avatarName: string,
  avatarCipher: string,
  avatarIP: string,
  text: string,
) => {
  return (
    text &&
    avatarCipher &&
    DB.postCommentary(avatarName, avatarCipher, avatarIP, getDatetime(), text)
  );
};

export const doModifyCommentary = async (
  commentaryID: number,
  avatarCipher: string,
  text: string,
) => {
  return (
    avatarCipher &&
    text &&
    DB.doModifyCommentary(commentaryID, avatarCipher, text)
  );
};

export const wipeCommentary = async (
  commentaryID: number,
  avatarCipher: string,
) => {
  return avatarCipher && DB.wipeCommentary(commentaryID, avatarCipher);
};
