import {
  doModifyCommentary as dbModifyCommentary,
  getCommentary as dbGetCommentary,
  postCommentary as dbPostCommentary,
  wipeCommentary as dbWipeCommentary,
} from "@/app/www/system/DB";
import { getDatetime } from "taehui-lib/date";

export const getCommentary = async () => {
  return dbGetCommentary();
};

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

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

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