package com.sjyt.icom.asst.context.handle.cmd;

import com.sjyt.icom.asst.common.enums.CmdEnum;
import com.sjyt.icom.asst.common.model.message.NewsLetter;
import com.sjyt.icom.asst.context.handle.msgtype.req.AvMsgHandleContext;
import com.sjyt.icom.asst.context.handle.msgtype.req.AvMsgHandleEvent;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * <p>音视频</p>
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/22 11:46
 */
@Component
@AllArgsConstructor
public class AvCmdHandle extends CmdHandle<NewsLetter> {
   private final AvMsgHandleContext msgHandleContext;
    /**
     * 执行链
     *
     * @param newsLetter t
     */
    @Override
    public void doChain(NewsLetter newsLetter) {
        boolean b1 = CmdEnum.V.getCode().equalsIgnoreCase(newsLetter.getMessage().getCmd());
        boolean b2 = CmdEnum.A.getCode().equalsIgnoreCase(newsLetter.getMessage().getCmd());
        CmdEnum cmdEnum = CmdEnum.of(newsLetter.getMessage().getCmd());
        if (b1 || b2){
            Optional.of(newsLetter).map(msg -> msg.getMessage().getBody()).ifPresent(body -> {
               // String key = (String) body.get(MsgTypeEnum.META);
                AvMsgHandleEvent event = AvMsgHandleEvent.builder().cmdEnum(cmdEnum).newsLetter(newsLetter).build();
                msgHandleContext.todo(event);
            });
        }
    }
}
