export default function helpers(pterodactyl: any) {
  return {
    // helper what return auth header
    async authHeader(contentType: string = "application/json") {
      return {
        Authorization: `Bearer ${pterodactyl.api_key}`,
        "Content-Type": contentType,
        Accept: "Application/vnd.pterodactyl.v1+json",
      };
    },

    // setter for api key
    async setApiKey(apiKey: string) {
      return (pterodactyl.api_key = apiKey);
    },

    // setter for server id
    async setServerID(serverID: string) {
      return (pterodactyl.server_id = serverID);
    },

    // setter for working directory
    async setWorkingDirectory(workingDirectory: string) {
      return (pterodactyl.workingDirectory = workingDirectory);
    },

    // getter for working directory
    async getWorkingDirectory() {
      return pterodactyl.workingDirectory;
    },

    // helper that get main site and get csrf token from it
    async getCsrfToken() {
      const response = await fetch(`${process.env.NEXT_PUBLIC_URL}`, {
        method: "GET",
      });
      const text = await response.text();
      const match = text.match(/<meta name="csrf-token" content="(.*)">/);
      const csrfToken = match ? match[1] : null;
      return csrfToken;
    },
  };
}
