package advice

import (
	"ai_scheduler/internal/biz"
	"ai_scheduler/internal/config"
	"ai_scheduler/internal/entitys"
	"ai_scheduler/internal/pkg"

	"github.com/gofiber/fiber/v2"
)

// AdvicerService 数据处理
type AdvicerService struct {
	adviceBiz *biz.AdviceAdvicerBiz
	cfg       *config.Config
}

// NewDataService
func NewAdvicerService(
	adviceBiz *biz.AdviceAdvicerBiz,
	cfg *config.Config,
) *AdvicerService {
	return &AdvicerService{
		adviceBiz: adviceBiz,
		cfg:       cfg,
	}
}

func (d *AdvicerService) AdvicerUpdate(c *fiber.Ctx) error {
	req := &entitys.AdvicerInitReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	id, err := d.adviceBiz.Update(c.UserContext(), req)
	return pkg.HandleResponse(c, int(id), err)
}

func (d *AdvicerService) AdvicerList(c *fiber.Ctx) error {
	req := &entitys.AdvicerListReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	list, err := d.adviceBiz.List(c.UserContext(), req)
	return pkg.HandleResponse(c, list, err)
}

func (d *AdvicerService) AdvicerVersionAdd(c *fiber.Ctx) error {
	req := &entitys.AdvicerVersionAddReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	id, err := d.adviceBiz.VersionAdd(c.UserContext(), req)
	return pkg.HandleResponse(c, id, err)
}

func (d *AdvicerService) AdvicerVersionUpdate(c *fiber.Ctx) error {
	req := &entitys.AdvicerVersionUpdateReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	return d.adviceBiz.VersionUpdate(c.UserContext(), req)
}

func (d *AdvicerService) AdvicerVersionList(c *fiber.Ctx) error {
	req := &entitys.AdvicerVersionListReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	list, err := d.adviceBiz.VersionList(c.UserContext(), req)
	return pkg.HandleResponse(c, list, err)
}

func (d *AdvicerService) AdvicerVersionDel(c *fiber.Ctx) error {
	req := &entitys.AdvicerVersionDelReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}

	return d.adviceBiz.VersionDel(c.UserContext(), req)
}
