package com.sckw.manage.controller;

import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.manage.model.vo.req.*;
import com.sckw.manage.service.KwmAddressService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author czh
 * @desc 地址管理
 * @date 2023/7/10
 */
@RestController
@RequestMapping("/kwmAddress")
public class KwmAddressController {

    @Autowired
    private KwmAddressService kwmAddressService;

    /**
     * @param reqVo 分页入参
     * @return HttpResult
     * @desc: 分页查询
     * @author: czh
     * @date: 2023/7/12
     */
    @PostMapping("/queryByPage")
    public HttpResult queryByPage(@RequestBody AddressQueryReqVo reqVo) {
        return HttpResult.ok(kwmAddressService.queryByPage(reqVo));
    }


    /**
     * @param reqVo 默认地址入参
     * @return HttpResult
     * @desc: 设置默认地址
     * @author: czh
     * @date: 2023/7/12
     */
    @PostMapping("/bindDefault")
    public HttpResult bindDefault(@Valid @RequestBody BindDefaultReqVo reqVo) {
        kwmAddressService.bindDefault(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    /**
     * @param reqVo 修改入参
     * @return HttpResult
     * @desc: 修改地址信息
     * @author: czh
     * @date: 2023/7/12
     */
    @PostMapping("/update")
    public HttpResult update(@Valid @RequestBody AddressUpdateReqVo reqVo) {
        kwmAddressService.update(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    /**
     * @param reqVo 修改入参
     * @return HttpResult
     * @desc: 修改地址信息
     * @author: czh
     * @date: 2023/7/12
     */
    @PostMapping("/add")
    public HttpResult add(@Valid @RequestBody AddressAddReqVo reqVo) {
        kwmAddressService.add(reqVo);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    /**
     * @param reqVo ids
     * @return HttpResult
     * @desc: 删除地址信息
     * @author: czh
     * @date: 2023/7/12
     */
    @PostMapping("/delete")
    public HttpResult delete(@Valid @RequestBody IdsReqVo reqVo) {
        kwmAddressService.delete(reqVo.getIds());
        return HttpResult.ok(HttpStatus.MSG_008);
    }


    /**
     * @param reqVo 查询入参
     * @desc: 导出
     * @author: czh
     * @date: 2023/7/12
     */
    @PostMapping(value = "export", produces = MediaType.APPLICATION_JSON_VALUE)
    public void export(@Valid @RequestBody AddressQueryReqVo reqVo, HttpServletResponse response) {
        kwmAddressService.export(reqVo, response);
    }

    /**
     * @desc: 查企业下的地址
     * @param: reqVo 企业id
     * @author: czh
     * @date 2023/7/18
     * @return HttpResult
     */
    @PostMapping("queryByEnt")
    public HttpResult queryByEnt(@RequestBody QueryByEntReqVo reqVo) {
        return HttpResult.ok(kwmAddressService.queryByEnt(reqVo));
    }

    /**
     * @param reqVo 主键
     * @return HttpResult
     * @desc: 查详情
     * @author: czh
     * @date: 2023/7/25
     */
    @PostMapping("detail")
    public HttpResult detail(@RequestBody IdsReqVo reqVo) {
        return HttpResult.ok(kwmAddressService.detail(reqVo.getId()));
    }

}
