import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.chat.ChatOwnerTotalDTO;
import com.gic.haoban.manage.api.dto.qdto.chat.GroupChatPlanSearchQDTO;
import com.gic.haoban.manage.api.dto.qdto.content.InteractRecordQDTO;
import com.gic.haoban.manage.api.enums.content.InteractRecordInfoDTO;
import com.gic.haoban.manage.api.enums.content.MaterialInteractRecordEventType;
import com.gic.haoban.manage.api.enums.content.TriggerCustomerChannelType;
import com.gic.haoban.manage.api.service.content.InteractRecordApiService;
import com.gic.haoban.manage.service.dao.mapper.chat.GroupChatPlanOwnerLogMapper;
import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanInteractRecordMapper;
import com.gic.haoban.manage.service.entity.content.TabHaobanInteractRecord;
import com.gic.haoban.manage.service.pojo.bo.content.InteractRecordBO;
import com.gic.haoban.manage.service.pojo.bo.content.MemberAttrChangeBO;
import com.gic.haoban.manage.service.pojo.bo.content.message.InteractRecordMessageBO;
import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO;
import com.gic.haoban.manage.service.service.content.InteractRecordService;
import com.gic.haoban.manage.service.service.content.message.InteractRecordMessageService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author MUSI
 * @Date 2023/3/29 3:16 PM
 * @Description
 * @Version
 **/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class InteractRecordTest {

    @Autowired
    private InteractRecordService interactRecordService;
    @Autowired
    private TabHaobanInteractRecordMapper interactRecordMapper;
    @Autowired
    private InteractRecordMessageService interactRecordMessageService;
    @Autowired
    InteractRecordApiService interactRecordApiService;


    String eid = "ff8080815dacd3a2015dacd3ef5c0000";
    String wxEid = "ca66a01b79474c40b3e7c7f93daf1a3b";
    String staffId = "e608b51b267e4943b87e222a343b4f25";
    String clerkId = "bcbfff6c8e2e40aaac795a99d0dde2aa";
    String memberId = "ff8080818147efc8018148d1759903c8";

    @Test
    public void queryInteractPageTest(){
        InteractRecordQDTO interactRecordQO = new InteractRecordQDTO();
        interactRecordQO.setClerkId(clerkId);
        interactRecordQO.setMemberId(memberId);
        ServiceResponse<Page<InteractRecordInfoDTO>> serviceResponse =
                interactRecordApiService.queryInteractRecordList(interactRecordQO);
        System.out.println(JSON.toJSONString(serviceResponse));
    }

    @Test
    public void dealRecordTest(){
        String businessId = "UUID.randomUUID().toString()";
        InteractRecordMessageBO message = new InteractRecordMessageBO();
        message.setClerkId(clerkId);
        message.setEnterpriseId(eid);
        message.setMemberId(memberId);
        message.setUnionId(memberId);
        message.setStoreId("ff8080818499a54801849ce85f9f003f");
        message.setMaterialId("123213");
        message.setChannelSource(TriggerCustomerChannelType.PYQ.getCode());
        message.setEventType(MaterialInteractRecordEventType.VISIT_PRODUCT.getCode());
        message.setGoodsId("fbc508e395f846ef9005852c420e1c23");
        message.setDurationTime(2000);
        message.setBusinessUUId(businessId);
        message.setLastAccessTime(new Date().getTime());
        interactRecordMessageService.dealRecord(message);
    }

    @Test
    public void test(){
        for (int i = 0; i < 10; i++) {
            System.out.println(MD5.create().digestHex("song"));
        }
    }

    @Autowired
    GroupChatPlanOwnerLogMapper groupChatPlanOwnerLogMapper;
    
    @Test
    public void caseWhenTest(){
        GroupChatPlanSearchQDTO search = new GroupChatPlanSearchQDTO();
        search.setWxEnterpriseId("f5f8c78e395e4ca1a493707316096097");
        List<ChatOwnerTotalDTO> chatOwnerTotalDTOS = groupChatPlanOwnerLogMapper.listOwnerLogPageForWxaTotal(search);
    }

    @Test
    public void mergeMember() {
        MemberAttrChangeBO memberAttrChangeBO = new MemberAttrChangeBO();
        memberAttrChangeBO.setMemberId(memberId);
        memberAttrChangeBO.setUnionId("orXl9tyHOI4qP1QxwVcA7A3sB7zg");
        memberAttrChangeBO.setOpt(MemberAttrChangeBO.MemberChangeOpt.MINI_APP_AUTHORIZED.getCode());
        interactRecordApiService.memberChangeMQ(JSON.toJSONString(memberAttrChangeBO));
    }

    @Test
    public void queryTest() {
        List<TabHaobanInteractRecord> interactRecords = interactRecordMapper.queryInteractRecordList(null);
    }
}
