package controller

import (
	"github.com/gofiber/fiber/v2"
	service "gitlab.com/mbugroup/lti-api.git/internal/modules/system-settings/services"
	"gitlab.com/mbugroup/lti-api.git/internal/response"
)

type SystemSettingController struct {
	Service service.SystemSettingService
}

func NewSystemSettingController(svc service.SystemSettingService) *SystemSettingController {
	return &SystemSettingController{Service: svc}
}

func (ctrl *SystemSettingController) GetAll(c *fiber.Ctx) error {
	settings, err := ctrl.Service.GetAll(c.Context())
	if err != nil {
		return err
	}
	return c.Status(fiber.StatusOK).JSON(response.Success{
		Code:    fiber.StatusOK,
		Status:  "success",
		Message: "Get all system settings successfully",
		Data:    settings,
	})
}

type setAllowNegativePakanOVKRequest struct {
	Value bool `json:"value"`
}

func (ctrl *SystemSettingController) SetAllowNegativePakanOVK(c *fiber.Ctx) error {
	var req setAllowNegativePakanOVKRequest
	if err := c.BodyParser(&req); err != nil {
		return fiber.NewError(fiber.StatusBadRequest, "Request body tidak valid")
	}
	if err := ctrl.Service.SetAllowNegativePakanOVK(c.Context(), req.Value); err != nil {
		return err
	}
	return c.Status(fiber.StatusOK).JSON(response.Common{
		Code:    fiber.StatusOK,
		Status:  "success",
		Message: "Setting berhasil diperbarui",
	})
}
