package com.sckw.address.controller;

import com.sckw.address.entity.vo.req.KwBusinessAddressListParam;
import com.sckw.address.entity.vo.req.KwBusinessAddressPageListParam;
import com.sckw.address.entity.vo.req.KwBusinessAddressParam;
import com.sckw.address.entity.vo.res.KwBusinessAddressListRes;
import com.sckw.address.service.KwAddressService;
import com.sckw.core.model.page.PageRes;
import com.sckw.core.web.response.HttpResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 地址服务
 * @author: Lt
 * @date: 2024-04-11
 */
@Validated
@RestController
@RequestMapping(value = "/address")
public class AddressController {

    @Autowired
    KwAddressService kwAddressService;

    /**
    * @Description: 地址新增
    * @Author: Lt
    * @Date: 2024/4/11 15:54
    */
    @PostMapping(value = "/save")
    public HttpResult addressCreate(@RequestBody @Valid KwBusinessAddressParam kwBusinessAddressParam)
    {
        return kwAddressService.addressCreate(kwBusinessAddressParam);
    }

    /**
     * @Description: 地址编辑
     * @Author: Lt
     * @Date: 2024/4/11 15:54
     */
    @PostMapping(value = "/update")
    public HttpResult addressUpdate(@RequestBody @Valid KwBusinessAddressParam kwBusinessAddressParam)
    {
        return kwAddressService.addressUpdate(kwBusinessAddressParam);
    }

    /**
    * @Description: 地址删除
    * @Author: Lt
    * @Date: 2024/4/11 16:43
    */
    @PostMapping(value = "/delete")
    public HttpResult delete(@RequestParam("id") String id){

        return kwAddressService.addressDelete(id);
    }

    /**
    * @Description: 地址查询
    * @Author: Lt
    * @Date: 2024/4/11 16:43
    */
    @GetMapping("/find")
    public HttpResult find(@RequestParam("id") String id){
        return kwAddressService.addressFind(id);
    }

    /**
    * @Description: 地址分页查询
    * @Author: Lt
    * @Date: 2024/4/11 16:51
    */
    @PostMapping(value = "/selectPageList")
    public HttpResult pageList(@RequestBody @Valid KwBusinessAddressPageListParam kwBusinessAddressListParam)
    {
        return kwAddressService.addressPageList(kwBusinessAddressListParam);
    }

    /**
     * @Description: 地址查询
     * @Author: Lt
     * @Date: 2024/4/11 16:51
     */
    @PostMapping(value = "/select")
    public HttpResult list(@RequestBody(required = false) KwBusinessAddressListParam kwBusinessAddressListParam)
    {
        PageRes<KwBusinessAddressListRes> list = kwAddressService.selectList(kwBusinessAddressListParam);
        return HttpResult.ok(list);
    }

}
