package logic

import (
	"audio_transcoder/internal/svc"
	"audio_transcoder/internal/types"
	"audio_transcoder/job"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type TranscoderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTranscoderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TranscoderLogic {
	return &TranscoderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TranscoderLogic) Transcoder(req *types.Request) (resp *types.Response, err error) {
	transcoder, err := job.Transcoder(l.svcCtx, &types.CallbackRequest{Path: req.Path})
	if err != nil {
		return nil, err
	}
	resp = &types.Response{
		Path:    transcoder.Path,
		Message: transcoder.Message,
	}
	return
}
