package persona

import (
	"context"
	"strings"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

type DeletePersonaCopyDraftLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeletePersonaCopyDraftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeletePersonaCopyDraftLogic {
	return &DeletePersonaCopyDraftLogic{ctx: ctx, svcCtx: svcCtx}
}

func (l *DeletePersonaCopyDraftLogic) DeletePersonaCopyDraft(req *types.CopyDraftPath) (*types.DeleteCopyDraftData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	personaID := strings.TrimSpace(req.ID)
	draftID := strings.TrimSpace(req.DraftID)
	if _, err := l.svcCtx.Persona.Get(l.ctx, tenantID, uid, personaID); err != nil {
		return nil, err
	}
	if err := l.svcCtx.CopyDraft.Delete(l.ctx, tenantID, uid, personaID, draftID); err != nil {
		return nil, err
	}
	return &types.DeleteCopyDraftData{
		DraftID: draftID,
		Message: "草稿已刪除",
	}, nil
}
