package controllers

import (
	"amocrm/internal/service"
	"amocrm/internal/tools"
	"github.com/gofiber/fiber/v2"
	"go.uber.org/zap"
)

type Deps struct {
	Service     *service.Service
	Logger      *zap.Logger
	Verify      *tools.Verify
	RedirectURL string
}

type Controller struct {
	service *service.Service
	logger  *zap.Logger
	verify  *tools.Verify
}

func NewController(deps Deps) *Controller {
	return &Controller{
		service: deps.Service,
		logger:  deps.Logger,
		verify:  deps.Verify,
	}
}

func (c *Controller) Register(router fiber.Router) {
	router.Patch("/users", c.UpdateListUsers)
	router.Get("/users", c.GettingUserWithPagination)
	router.Delete("/account", c.SoftDeleteAccount)
	router.Get("/account", c.GetCurrentAccount)
	router.Post("/account", c.ConnectAccount)
	router.Get("/steps", c.GetStepsWithPagination)
	router.Patch("/steps", c.UpdateListSteps)
	router.Patch("/pipelines", c.UpdateListPipelines)
	router.Get("/pipelines", c.GetPipelinesWithPagination)
	router.Patch("/rules/:quizID", c.ChangeQuizSettings)
	router.Post("/rules/:quizID", c.SetQuizSettings)
	router.Get("/rules/:quizID", c.GettingQuizRules)
	router.Get("/tags", c.GetTagsWithPagination)
	router.Patch("/tags", c.UpdateListTags)
	router.Get("/fields", c.GetFieldsWithPagination)
	router.Patch("/fields", c.UpdateListCustom)
}

func (c *Controller) Name() string {
	return "amocrm"
}

type WebhookController struct {
	service     *service.Service
	logger      *zap.Logger
	verify      *tools.Verify
	redirectURL string
}

func NewWebhookController(deps Deps) *WebhookController {
	return &WebhookController{
		service:     deps.Service,
		logger:      deps.Logger,
		verify:      deps.Verify,
		redirectURL: deps.RedirectURL,
	}
}

func (c *WebhookController) Register(router fiber.Router) {
	//todo поменять как было GET webhook/create
	router.Get("/create", c.WebhookCreate)
	//todo поменять как было webhook/delete
	router.Delete("/delete", c.WebhookDelete)
}

func (c *WebhookController) Name() string {
	return "webhook"
}
