package advice

import (
	"ai_scheduler/internal/biz"
	"ai_scheduler/internal/config"
	errorcode "ai_scheduler/internal/data/error"
	"ai_scheduler/internal/entitys"
	"ai_scheduler/internal/pkg"

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

// ProjectService 数据处理
type ProjectService struct {
	adviceProjectBiz *biz.AdviceProjectBiz
	cfg              *config.Config
}

// NewProjectService
func NewProjectService(
	adviceProjectBiz *biz.AdviceProjectBiz,
	cfg *config.Config,
) *ProjectService {
	return &ProjectService{
		adviceProjectBiz: adviceProjectBiz,
		cfg:              cfg,
	}
}

func (d *ProjectService) BaseInit(c *fiber.Ctx) error {
	req := &entitys.AdvicerProjectBaseAddReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	add, err := d.adviceProjectBiz.BaseAdd(c.UserContext(), req)
	return pkg.HandleResponse(c, add, err)
}

func (d *ProjectService) BaseUpdate(c *fiber.Ctx) error {
	req := &entitys.AdvicerProjectBaseUpdateReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	if req.ProjectId == 0 {
		return errorcode.ParamErr("projectId is empty")
	}
	return d.adviceProjectBiz.BaseUpdate(c.UserContext(), req)
}

func (d *ProjectService) Add(c *fiber.Ctx) error {
	req := &entitys.AdvicerProjectAddReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	id, err := d.adviceProjectBiz.Add(c.UserContext(), req)
	return pkg.HandleResponse(c, id, err)
}

func (d *ProjectService) Update(c *fiber.Ctx) error {
	req := &entitys.AdvicerrProjectUpdateReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	return d.adviceProjectBiz.Update(c.UserContext(), req)
}

func (d *ProjectService) Info(c *fiber.Ctx) error {
	req := &entitys.AdvicerProjectInfoReq{}
	if err := c.BodyParser(req); err != nil {
		return err
	}
	list, err := d.adviceProjectBiz.Info(c.UserContext(), req)
	return pkg.HandleResponse(c, list, err)
}
