package com.sckw.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sckw.core.exception.SystemException;
import com.sckw.core.model.page.PageHelperUtil;
import com.sckw.core.model.page.PageResult;
import com.sckw.core.web.context.LoginUserHolder;
import com.sckw.core.web.response.HttpResult;
import com.sckw.system.model.vo.req.KwsSpecialAddReqVo;
import com.sckw.system.model.vo.req.KwsSpecialUpdateReqVo;
import com.sckw.system.model.vo.res.KwsSpecialEntResVo;
import com.sckw.system.model.vo.res.KwsSpecialResVo;
import com.sckw.system.service.KwsSpecialService;
import jakarta.validation.Valid;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @desc 专场
 * @author zk
 * @date 2023/12/11 0011
 */
@RestController
@RequestMapping("/kwsSpecial")
public class KwsSpecialController {

    @Autowired
    KwsSpecialService kwsSpecialService;

    /**
     * @param id 主键ID
     * @desc 根据主键查询
     * @author zk
     * @date 2023/12/13
     **/
    @GetMapping("/detail")
    public HttpResult selectByKey(Long id) throws SystemException {
        //车辆信息
        KwsSpecialResVo truckDetailVo = kwsSpecialService.detail(id);
        return HttpResult.ok(truckDetailVo);
    }

    /**
     * @param params {page：页数、pageSize：每页条数、。。。}
     * @desc 分页查询
     * @author zk
     * @date 2023/12/13
     **/
    @PostMapping("/select")
    public HttpResult findPage(@RequestBody Map<String, Object> params) throws SystemException {
        // 设置分页参数
        PageHelper.startPage(PageResult.getPage(params), PageResult.getPageSize(params));
        List<KwsSpecialResVo> list = kwsSpecialService.findPage(params);
        PageResult pageResult = PageHelperUtil.getPageResult(new PageInfo<>(list));
        return HttpResult.ok(pageResult);
    }

    /**
     * @param params {page：页数、pageSize：每页条数、。。。}
     * @desc 分页查询
     * @author zk
     * @date 2023/12/13
     **/
    @PostMapping("/specialSelect")
    public HttpResult specialSelect(@RequestBody Map<String, Object> params) throws SystemException {
        // 设置分页参数
        PageHelper.startPage(PageResult.getPage(params), PageResult.getPageSize(params));
        List<KwsSpecialEntResVo> list = kwsSpecialService.findSpecialPage(params);
        PageResult pageResult = PageHelperUtil.getPageResult(new PageInfo<>(list));
        return HttpResult.ok(pageResult);
    }

    /**
     * @param params {。。。}
     * @desc 查询
     * @author zk
     * @date 2023/12/13
     **/
    @PostMapping("/findList")
    public HttpResult findList(@RequestBody Map<String, Object> params) throws SystemException {
        return HttpResult.ok(kwsSpecialService.findList(params));
    }

    /**
     * @param params 新增参数
     * @return HttpResult
     * @desc 新增专场
     * @author czh
     * @date 2023/12/13
     */
    @PostMapping("/add")
    public HttpResult add(@Valid @RequestBody KwsSpecialAddReqVo params) throws SystemException{
        return kwsSpecialService.add(params);
    }

    /**
     * @param params {}
     * @desc 更新
     * @author zk
     * @date 2023/12/13
     **/
    @PostMapping("/update")
    public HttpResult update(@Valid @RequestBody KwsSpecialUpdateReqVo params) throws SystemException {
        return kwsSpecialService.update(params);
    }

    /**
     * @param {ids：主键ID（多个以逗号隔开）}
     * @desc 删除
     * @author zk
     * @date 2023/12/13
     **/
    @DeleteMapping("/dels")
    public HttpResult del(@RequestParam String ids) throws SystemException {
        return kwsSpecialService.del(ids);
    }

    /**
     * @param params {}
     * @desc 加入专场
     * @author zk
     * @date 2023/12/13
     **/
    @PostMapping("/joinSpecial")
    public HttpResult joinSpecial(@Valid @RequestBody HashMap<String, Object> params) throws SystemException {
        return kwsSpecialService.joinSpecial(params);
    }

    /**
     * @param params {}
     * @desc 退出专场
     * @author zk
     * @date 2023/12/13
     **/
    @PostMapping("/exitSpecial")
    public HttpResult exitSpecial(@Valid @RequestBody HashMap<String, Object> params) throws SystemException {
        return kwsSpecialService.exitSpecial(params);
    }

    /**
     * @param domain 域名
     * @desc 专场详情
     * @author zk
     * @date 2023/12/13
     **/
    @GetMapping("/findSpecial")
    public HttpResult findSpecial(String domain){
        return HttpResult.ok(kwsSpecialService.findSpecial(domain));
    }
}
