package admin

import (
	"net/http"

	"metazone.cc/metalab/internal/common"
	"metazone.cc/metalab/internal/model"

	"github.com/gin-gonic/gin"
)

// AdminEnergyController 后台域能管理控制器
type AdminEnergyController struct {
	energySvc adminEnergyUseCase
}

// NewAdminEnergyController 构造函数
func NewAdminEnergyController(energySvc adminEnergyUseCase) *AdminEnergyController {
	return &AdminEnergyController{energySvc: energySvc}
}

// EnergyPage 域能管理页面（公户余额 + 用户域能调整）
func (ac *AdminEnergyController) EnergyPage(c *gin.Context) {
	balance := 0
	if b, err := ac.energySvc.GetFundBalance(); err == nil {
		balance = b
	}
	c.HTML(http.StatusOK, "admin/energy/index.html", common.BuildAdminPageData(c, gin.H{
		"Title":              "域能管理",
		"ExtraCSS":           "/admin/static/css/energy.css",
		"ExtraJS":            "/admin/static/js/energy.js",
		"FundBalance":        balance,
		"FundBalanceDisplay": float64(balance) / 10,
	}))
}

// EnergyLogPage 域能日志页面
func (ac *AdminEnergyController) EnergyLogPage(c *gin.Context) {
	c.HTML(http.StatusOK, "admin/energy/logs.html", common.BuildAdminPageData(c, gin.H{
		"Title":    "域能日志",
		"ExtraCSS": "/admin/static/css/energy.css",
		"ExtraJS":  "/admin/static/js/energy.js",
		"LogTypes": model.EnergyLogDisplayNames,
	}))
}

// FundLogPage 公户流水页面
func (ac *AdminEnergyController) FundLogPage(c *gin.Context) {
	c.HTML(http.StatusOK, "admin/energy/fund_logs.html", common.BuildAdminPageData(c, gin.H{
		"Title":    "公户流水",
		"ExtraCSS": "/admin/static/css/energy.css",
		"ExtraJS":  "/admin/static/js/energy.js",
		"LogTypes": model.FundLogDisplayNames,
	}))
}
