import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.content.api.qdto.activity.ContentActivityQDTO;
import com.gic.haoban.manage.api.dto.chat.GroupChatActivityRewardDTO;
import com.gic.haoban.manage.api.dto.chat.GroupChatActivityRewardDetailDTO;
import com.gic.haoban.manage.api.dto.chat.GroupChatHmDTO;
import com.gic.haoban.manage.api.qdto.chat.GroupChatActivityHmQDTO;
import com.gic.haoban.manage.api.qdto.chat.GroupChatActivityJoinQDTO;
import com.gic.haoban.manage.api.qdto.chat.GroupChatActivityQDTO;
import com.gic.haoban.manage.api.service.chat.GroupChatActivityApiService;
import com.gic.haoban.manage.api.service.chat.GroupChatActivityShareApiService;
import com.gic.haoban.manage.service.pojo.bo.chat.GroupChatActivityBaseContext;
import com.gic.haoban.manage.service.pojo.bo.chat.GroupChatActivityContext;
import com.gic.haoban.manage.service.service.chat.GroupChatActivityInviteLogService;
import com.gic.haoban.manage.service.service.chat.GroupChatActivityRewardLogService;
import com.gic.haoban.manage.service.service.chat.GroupChatActivityService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.*;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class GroupChatTest {

    private static Logger logger = LoggerFactory.getLogger(GroupChatTest.class);

    @Autowired
    private GroupChatActivityApiService groupChatActivityApiService;
    @Autowired
    private GroupChatActivityShareApiService groupChatActivityShareApiService;
    @Autowired
    private GroupChatActivityInviteLogService groupChatActivityInviteLogService;

    @Test
    public void saveActivity() throws Exception{
        GroupChatActivityQDTO qdto = new GroupChatActivityQDTO();
        qdto.setActivityName("测试活动2");
        qdto.setStartDate(new Date("2024/10/11"));
        qdto.setEndDate(new Date("2025/10/10"));
        qdto.setActivityImg("123");
        qdto.setActivityInviteImg("123");
        qdto.setActivityDesc("123");
        qdto.setActivityShareTitle("123");
        qdto.setActivityShareImg("123");
        qdto.setActivityPosterImg("123");
        qdto.setInviteRewardType(2);
        qdto.setJoinType(2);
//        qdto.setJoinRule();
        qdto.setJoinChatHmId(709467854075881635L);
        qdto.setInviteType(1);
        qdto.setInviteMemberType(1);
        qdto.setLabelFlag(0);
//        qdto.setLabelJson();
        qdto.setExceptionNotice(0);
        qdto.setExceptionNoticeNum(0);
        qdto.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
        qdto.setWxEnterpriseId("ca66a01b79474c40b3e7c7f93daf1a3b");
        qdto.setCreatorId("fefd1c81641711e69d0818c58a146fd2");
        qdto.setCreatorName("达摩管理");
        List<GroupChatActivityRewardDTO> rewardList = new ArrayList<>();
        GroupChatActivityRewardDTO rewardDTO = new GroupChatActivityRewardDTO();
        rewardDTO.setInviteNumber(1);
        rewardDTO.setInviteLevel(1);
        rewardDTO.setRewardInvite(1);
        rewardDTO.setLimitReward(3);
        Map<Integer, List<GroupChatActivityRewardDTO>> rewardMap = new HashMap<>();
        List<GroupChatActivityRewardDetailDTO> detailList = new ArrayList<>();
        GroupChatActivityRewardDetailDTO rewardDetail = new GroupChatActivityRewardDetailDTO();
        rewardDetail.setRewardType(1);
        rewardDetail.setRewardValue("2");
        rewardDetail.setRewardName("2积分");
        detailList.add(rewardDetail);
        rewardDTO.setDetailList(detailList);
        rewardList.add(rewardDTO);
        rewardMap.put(1, rewardList);
        rewardDTO = new GroupChatActivityRewardDTO();
        rewardDTO.setInviteNumber(1);
        rewardDTO.setInviteLevel(1);
        rewardDTO.setRewardInvite(2);
        rewardDTO.setLimitReward(1);
        List<GroupChatActivityRewardDetailDTO> detailList2 = new ArrayList<>();
        GroupChatActivityRewardDetailDTO rewardDetail2 = new GroupChatActivityRewardDetailDTO();
        rewardDetail2.setRewardType(1);
        rewardDetail2.setRewardValue("8");
        rewardDetail2.setRewardName("8积分");
        detailList2.add(rewardDetail2);
        rewardDTO.setDetailList(detailList2);
        rewardList.add(rewardDTO);
        rewardMap.put(2, rewardList);
        qdto.setRewardMap(rewardMap);
        List<GroupChatActivityJoinQDTO> joinList = new ArrayList<>();
        GroupChatActivityJoinQDTO join = new GroupChatActivityJoinQDTO();
        join.setMemberType(0);
        join.setFilterJson("");
        join.setFilterJsonView("");
        join.setIndex(2);
        join.setChatHmId(709467854075881635L);
        joinList.add(join);
        qdto.setJoinList(joinList);
        join = new GroupChatActivityJoinQDTO();
        join.setMemberType(0);
        join.setFilterJson("");
        join.setFilterJsonView("");
        join.setIndex(1);
        join.setChatHmId(709467854075881635L);
        joinList.add(join);
        qdto.setJoinList(joinList);
        ServiceResponse<Long> response = groupChatActivityApiService.saveActivity(qdto);
        System.out.println(JSONObject.toJSONString(response));
    }

    @Test
    public void listGroupChatHm() throws Exception{
        GroupChatActivityHmQDTO groupChatActivityHmQDTO = new GroupChatActivityHmQDTO();
        groupChatActivityHmQDTO.setChatActivityId(716721754221821953L);
        groupChatActivityHmQDTO.setInviterMemberId("ff808081906def5201907645bfc7005a");
        groupChatActivityHmQDTO.setInviteeMemberId("ff8080818215878101821949a845003c");
        groupChatActivityHmQDTO.setInviteeUnionId("123456");
        groupChatActivityHmQDTO.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
        groupChatActivityHmQDTO.setDistrictCode("330100");
        groupChatActivityHmQDTO.setLatitude("30.247100");
        groupChatActivityHmQDTO.setLongitude("120.209000");
        groupChatActivityHmQDTO.setSkipArea(false);
        ServiceResponse<List<GroupChatHmDTO>> listServiceResponse = groupChatActivityShareApiService.listGroupChatHm(groupChatActivityHmQDTO);
        System.out.println(JSONObject.toJSONString(listServiceResponse));
    }

    @Test
    public void groupChatInviteMQ() throws Exception{
//        groupChatActivityInviteLogService.groupChatInviteMQ("ff8080815dacd3a2015dacd3ef5c0000","123456",717384135185809471L);
    }

    @Test
    public void dealRewardAndSaveLog() throws Exception{
        GroupChatActivityBaseContext context = new GroupChatActivityBaseContext();
        context.setChatUserId(717384135185809471L);
        context.setChatActivityId(716721754221821953L);
        context.setInviterMemberId("ff808081906def5201907645bfc7005a");
        context.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
        groupChatActivityInviteLogService.groupChatInvite(context);
    }
}
