---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by hartnett.
--- DateTime: 2019/11/11 16:13
---

local core = require("apisix.core")
local exchange_ews = require("apisix.plugins.exchange-ews.exchange-ews")

local plugin_name = "exchange-ews"

local schema = {
    type = "object",
    properties = {
        debug = { type = "boolean",
                  enum = { true, false },
        },
        run_mode = {
            type = "string",
            enum = { "normal", "zero_trust" }
        }
    },
    required = { "run_mode" }
}

local _M = {
    version = 0.1,
    priority = 2003,
    name = plugin_name,
    schema = schema,
}

function _M.check_schema(conf)
    local ok, err = core.schema.check(schema, conf)

    if not ok then
        return false, err
    end

    return true
end


-- access阶段，验证电脑端设备是否允许访问
function _M.access(conf, ctx)
    -- core.log.warn("plugin access phase, conf: ", core.json.encode(conf))
    exchange_ews.ews(conf, ctx)
end

-- 用户未激活前，过滤掉返回的信息
function _M.body_filter(conf, ctx)
    -- core.log.warn("plugin access phase, conf: ", core.json.encode(conf))
    exchange_ews.replace_body()
end

-- 用户未激活前，过滤掉返回的信息
function _M.header_filter(conf, ctx)
    -- core.log.warn("plugin access phase, conf: ", core.json.encode(conf))
    exchange_ews.replace_header()
end

return _M