package com.ruoyi.xq.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.BeanConvertUtil;
import com.ruoyi.xq.domain.AreaCode;
import com.ruoyi.xq.dto.app.areacode.AreaCodeHomeVo;
import com.ruoyi.xq.dto.app.areacode.AreaCodeQuery;
import com.ruoyi.xq.dto.app.areacode.AreaCodeTree;
import com.ruoyi.xq.dto.app.setting.AgreementDTO;
import com.ruoyi.xq.enums.common.SystemConfigEnum;
import com.ruoyi.xq.manager.SystemConfigManager;
import com.ruoyi.xq.mapper.AreaCodeMapper;
import com.ruoyi.xq.service.AgreementSettingService;
import com.ruoyi.xq.service.AreaCodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/setting")
@Tag(name = "获取设置相关接口")
@SaIgnore
public class SettingAppController {

    @Autowired
    private AgreementSettingService agreementSettingService;
    @Autowired
    private AreaCodeService areaCodeService;
    @Autowired
    private SystemConfigManager systemConfigManager;

    @GetMapping("/agreement/user")
    @Operation(summary = "获取用户协议")
    public R<AgreementDTO> userAgreement() {
        String userAgreement = agreementSettingService.getAgreementSetting().getUserAgreement();
        return R.ok(new AgreementDTO(userAgreement));
    }

    @GetMapping("/agreement/privacy")
    @Operation(summary = "获取隐私协议")
    public R<AgreementDTO> privacyAgreement() {
        String privacyAgreement = agreementSettingService.getAgreementSetting().getPrivacyAgreement();
        return R.ok(new AgreementDTO(privacyAgreement));
    }

    @Resource
    private AreaCodeMapper areaCodeMapper;

    @GetMapping("/areaCode/homeCity")
    @Operation(summary = "获取首页城市选择列表")
    public R<List<AreaCodeHomeVo>> homeCity(){
        List<AreaCodeHomeVo> vos = areaCodeMapper.homeCity();
        return R.ok(vos);
    }


    @GetMapping("/areaCode/list")
    @Operation(summary = "获取省市区编码接口")
    public R<List<AreaCode>> listAreaCode(AreaCodeQuery query){
        List<AreaCode> list = areaCodeService.listAreaCode(query);
        return R.ok(list);
    }

    @GetMapping("/areaCode/tree")
    @Operation(summary = "获取所有省市区编码")
    public R<List<AreaCodeTree>> areaCodeTree(){
        List<AreaCodeTree> node = areaCodeService.tree();
        return R.ok(node);
    }

    @GetMapping("/customerService/pic")
    @Operation(summary = "获取客服二维码")
    @SaIgnore
    public R<Map<String,String>> customerService(){
        String url = systemConfigManager.getSystemConfig(SystemConfigEnum.CUSTOMER_SERVICE_URL);
        Map<String,String> map = new HashMap<>();
        map.put("customerService",url);
        return R.ok(map);
    }

}
