package com.corewing.app.modules.app;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.corewing.app.common.Result;
import com.corewing.app.common.annotation.CommonLog;
import com.corewing.app.entity.PrivacyPolicy;
import com.corewing.app.service.PrivacyPolicyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

/**
 * 隐私政策与协议
 */
@Api(tags = "隐私政策与协议")
@Controller
@RequestMapping("/privacy_policy")
public class AppPrivacyPolicyController {

    @Resource
    private PrivacyPolicyService privacyPolicyService;

    /**
     * 隐私政策列表
     * @return
     */
    @CommonLog("隐私政策列表")
    @ApiOperation("隐私政策列表")
    @GetMapping("/view_list/{lang}")
    public String viewList(@PathVariable String lang, ModelMap modelMap) {
        List<PrivacyPolicy> list = privacyPolicyService.list();
        modelMap.put("list", list);
        // 获取最新更新时间
        modelMap.put("lastUpdateTime", privacyPolicyService.getLastUpdateTime());
        return "privacyPolicy/index";
    }

    /**
     * 根据类型获取集合数据
     * @param category
     * @return
     */
    @CommonLog("根据类型获取集合数据")
    @ApiOperation("根据类型获取集合数据")
    @GetMapping("/getListByCategory/{category}")
    @ResponseBody
    public Result<PrivacyPolicy> getListByCategory(@PathVariable Integer category) {
        LambdaQueryWrapper<PrivacyPolicy> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PrivacyPolicy::getCategory, category);
        return Result.success(privacyPolicyService.getOne(wrapper));
    }

}
