package chapter

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

	"server/api/chapter/v1"
)

func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) {
	out, err := service.Chapter().Create(ctx, &model.ChapterAddIn{
		BookId:        req.BookId,
		Content:       req.Content,
		IsLocked:      req.IsLocked,
		RequiredScore: req.RequiredScore,
		Sort:          req.Sort,
		Title:         req.Title,
		WordCount:     req.WordCount,
	})
	if err != nil {
		return nil, err
	}
	return &v1.AddRes{
		Success: out.Success,
	}, nil
}
