<script>
import {authenticatedRequest} from "@/components/session/authenticatedRequest.vue";
import {handleEconomicError} from "@/components/request/HandleEconomicError.vue";

/**
 * The Email -> Config object
 */
export const Config = {
    get: async ( variable ) => {
      return authenticatedRequest(
          "/email/config?variable=" + variable,
          "GET")
    },
    get_all: async () => {
      return authenticatedRequest(
          "/email/config",
          "GET")
    },
    set: async ( variable, value ) => {
      return authenticatedRequest(
          "/email/config",
          "POST",
          {
            variable: variable,
            value: value
          })
    },
    keys: {
      smtp_host: {
        get: async () => {
          return Config.get("smtp_host");
        },
        set: async (value) => {
          return Config.set("smtp_host", value);
        },
      },
      smtp_port: {
        get: async () => {
          return Config.get("smtp_port");
        },
        set: async (value) => {
          return Config.set("smtp_port", parseInt(value));
        },
      },
      smtp_username: {
        get: async () => {
          return Config.get("smtp_username");
        },
        set: async (value) => {
          return Config.set("smtp_username", value);
        },
      },
      smtp_password: {
        get: async () => {
          return Config.get("smtp_password");
        },
        set: async (value) => {
          return Config.set("smtp_password", value);
        },
      },
      smtp_encryption: {
        get: async () => {
          return Config.get("smtp_encryption");
        },
        set: async (value) => {
          return Config.set("smtp_encryption", value);
        },
      },
      smtp_from: {
        get: async () => {
          return Config.get("smtp_from");
        },
        set: async (value) => {
          return Config.set("smtp_from", value);
        },
      },
      smtp_from_name: {
        get: async () => {
          return Config.get("smtp_from_name");
        },
        set: async (value) => {
          return Config.set("smtp_from_name", value);
        },
      },
      smtp_reply_to: {
        get: async () => {
          return Config.get("smtp_reply_to");
        },
        set: async (value) => {
          return Config.set("smtp_reply_to", value);
        },
      },
      smtp_reply_to_name: {
        get: async () => {
          return Config.get("smtp_reply_to_name");
        },
        set: async (value) => {
          return Config.set("smtp_reply_to_name", value);
        },
      },
      mailersend_enabled: {
        get: async () => {
          return Config.get("mailersend_enabled");
        },
        set: async (value) => {
          return Config.set("mailersend_enabled", value);
        },
      },
      mailersend_api_key: {
        get: async () => {
          return Config.get("mailersend_api_key");
        },
        set: async (value) => {
          return Config.set("mailersend_api_key", value);
        },
      },
    },
    enabled: {
      get: async () => {
        return Config.get("enabled");
      },
      set: async (enabled) => {
        return Config.set("enabled", enabled);
      },
  },
};

</script>