package com.cool.store.service.impl;

import com.cool.store.dao.HyAdvancedSettingDAO;
import com.cool.store.entity.HyAdvancedSettingDO;
import com.cool.store.request.AdvancedSettingRequest;
import com.cool.store.service.AdvanceSettingService;
import com.cool.store.vo.AdvancedSettingVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author suzhuhong
 * @Date 2023/6/14 20:31
 * @Version 1.0
 */
@Service
public class AdvanceSettingServiceImpl implements AdvanceSettingService {

    @Resource
    HyAdvancedSettingDAO hyAdvancedSettingDAO;


    @Override
    public Boolean addOrUpdateAdvanceSetting(String userId, AdvancedSettingRequest advancedSettingRequest) {
        if (advancedSettingRequest.getId()!=null){
            //修改
            updateAdvanceSetting(userId,advancedSettingRequest);
            return Boolean.TRUE;
        }
        HyAdvancedSettingDO hyAdvancedSettingDO = new HyAdvancedSettingDO();
        hyAdvancedSettingDO.setCreateUserId(userId);
        hyAdvancedSettingDO.setPartnerUrl(advancedSettingRequest.getPartnerUrl());
        hyAdvancedSettingDO.setTencentVideoAccount(advancedSettingRequest.getTencentVideoAccount());
        hyAdvancedSettingDO.setTencentVideoKey(advancedSettingRequest.getTencentVideoKey());
        hyAdvancedSettingDAO.insertSelective(hyAdvancedSettingDO);
        return Boolean.TRUE;
    }

    private Boolean updateAdvanceSetting(String userId, AdvancedSettingRequest advancedSettingRequest) {
        HyAdvancedSettingDO hyAdvancedSettingDO = new HyAdvancedSettingDO();
        hyAdvancedSettingDO.setUpdateUserId(userId);
        hyAdvancedSettingDO.setId(advancedSettingRequest.getId());
        hyAdvancedSettingDO.setPartnerUrl(advancedSettingRequest.getPartnerUrl());
        hyAdvancedSettingDO.setTencentVideoAccount(advancedSettingRequest.getTencentVideoAccount());
        hyAdvancedSettingDO.setTencentVideoKey(advancedSettingRequest.getTencentVideoKey());
        hyAdvancedSettingDAO.updateByPrimaryKeySelective(hyAdvancedSettingDO);
        return Boolean.TRUE;
    }

    @Override
    public AdvancedSettingVO getAdvancedSettingDetail() {
        HyAdvancedSettingDO hyAdvancedSettingDO = hyAdvancedSettingDAO.selectAdvanceSetting();
        if (hyAdvancedSettingDO==null){
            return null;
        }
        AdvancedSettingVO advancedSettingVO = new AdvancedSettingVO();
        advancedSettingVO.setId(hyAdvancedSettingDO.getId());
        advancedSettingVO.setPartnerUrl(hyAdvancedSettingDO.getPartnerUrl());
        advancedSettingVO.setTencentVideoAccount(hyAdvancedSettingDO.getTencentVideoAccount());
        advancedSettingVO.setTencentVideoKey(hyAdvancedSettingDO.getTencentVideoKey());
        return advancedSettingVO;
    }
}
