package chapter

import (
	"context"
	v1 "server/api/chapter/v1"
	"server/internal/model"
	"server/internal/service"
)

func (c *ControllerV1) AppDetail(ctx context.Context, req *v1.AppDetailReq) (res *v1.AppDetailRes, err error) {
	out, err := service.Chapter().AppDetail(ctx, &model.ChapterAppDetailIn{
		Id: req.Id,
	})
	if err != nil {
		return nil, err
	}

	return &v1.AppDetailRes{
		Id:            out.Id,
		BookId:        out.BookId,
		Title:         out.Title,
		Content:       out.Content,
		WordCount:     out.WordCount,
		Sort:          out.Sort,
		IsLocked:      out.IsLocked,
		RequiredScore: out.RequiredScore,
		UpdatedAt:     out.UpdatedAt.String(),
	}, nil
}
