package main

import (
    "github.com/gofiber/fiber/v2"
    "log"
    "time"
)

type StatusResult struct {
    Code      string `json:"code"`
    Message   string `json:"msg"`
    Timestamp int64  `json:"timestamp"`
}

type StatusResultEx struct {
    StatusResult
    Scene      string `json:"scene"`
    SequenceId int64  `json:"sequenceId"`
}

func failureResponse(ctx *fiber.Ctx, code string, msg string, stat int) error {
    log.Println("failureResponse:> ", ctx.Request().URI(), msg)
    ctx.Response().SetStatusCode(stat)
    var ret = make(map[string]interface{})
    ret["status"] = StatusResult{Code: code, Message: msg, Timestamp: time.Now().Unix()}
    return ctx.JSON(ret)
}

func successResponse(ctx *fiber.Ctx, msg string) error {
    var ret = make(map[string]interface{})
    ret["status"] = StatusResult{Code: "0", Message: msg, Timestamp: time.Now().Unix()}
    return ctx.JSON(ret)
}

func successResponseData(ctx *fiber.Ctx, msg string, data interface{}) error {
    var ret = make(map[string]interface{})
    ret["status"] = StatusResult{Code: "0", Message: msg, Timestamp: time.Now().Unix()}
    ret["data"] = data
    return ctx.JSON(ret)
}

func successResponseEx(ctx *fiber.Ctx, msg string, scene string, seq int64) error {
    var ret = make(map[string]interface{})
    ret["status"] = StatusResultEx{
        StatusResult: StatusResult{
            Code:      "0",
            Message:   msg,
            Timestamp: time.Now().Unix(),
        },
        SequenceId: seq,
        Scene:      scene,
    }
    return ctx.JSON(ret)
}
