package chapter

import (
	"context"
	"server/internal/model"
	"server/internal/service"

	"server/api/chapter/v1"
)

func (c *ControllerV1) Edit(ctx context.Context, req *v1.EditReq) (res *v1.EditRes, err error) {
	out, err := service.Chapter().Update(ctx, &model.ChapterEditIn{
		Id:            req.Id,
		BookId:        req.BookId,
		Title:         req.Title,
		Sort:          req.Sort,
		IsLocked:      req.IsLocked,
		Content:       req.Content,
		WordCount:     req.WordCount,
		RequiredScore: req.RequiredScore,
	})
	if err != nil {
		return nil, err
	}
	return &v1.EditRes{
		Success: out.Success,
	}, nil
}
