package dto

import (
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"runtime/debug"
)

func BadRequest(c *gin.Context, err error) {
	log.Printf("err: %+v", err)
	debug.PrintStack()
	c.JSON(http.StatusBadRequest, Response{
		Status:  0,
		Message: err.Error(),
	})
}

func Error(c *gin.Context, err error) {
	log.Printf("err: %+v", err)
	debug.PrintStack()
	c.JSON(http.StatusInternalServerError, Response{
		Status:  0,
		Message: err.Error(),
	})
}

func NewOkResponse() Response {
	return Response{Status: 1, Message: "ok"}
}

type Response struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

type RegisterResponse struct {
	Response
	Data RegisterResult `json:"data"`
}

type RegisterResult struct {
	Success bool `json:"success"`
}

type ListResponse struct {
	Response
	Data []Node `json:"data"`
}

type DetailResponse struct {
	Response
	Data Node `json:"data"`
}

type Node struct {
	CountryCode string `json:"countryCode"`
	CountryName string `json:"countryName"`
	Ip          string `json:"ip"`
	Icon        string `json:"icon"`
}

type ConfigResponse struct {
	Response
	Data ConfigResult `json:"data"`
}

type ConfigResult struct {
	FreeTrialDuration uint64 `json:"freeTrialDuration"`
	Timestamp         int64  `json:"timestamp"`
	Node              Node   `json:"node"`
}
