package com.yuchen.saas.park.service.controller.property;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.property.PropertyOwnerResidentDto;
import com.yuchen.saas.park.api.dto.property.PropertyUserHouseDto;
import com.yuchen.saas.park.api.dto.property.PropertyUserHouseQueryDto;
import com.yuchen.saas.park.api.dto.property.PropertyVerifyCodeDto;
import com.yuchen.saas.park.api.vo.property.PropertyOwnerResidentListVo;
import com.yuchen.saas.park.api.vo.property.PropertyUserHouseBindResVo;
import com.yuchen.saas.park.api.vo.property.PropertyUserHouseListVo;
import com.yuchen.saas.park.service.service.property.IPropertyUserHouseService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Author 蔡文强
 * @Date 2023/11/28 10:56
 * @Description 用户房产表 前端控制器
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/propertyUserHouse")
public class PropertyUserHouseController {

    @Resource
    private IPropertyUserHouseService baseService;

    /**
     * 用户绑定房产
     * @param userHouseDto 用户绑定房产Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/bindHouse")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "用户绑定房产", notes = "用户绑定房产")
    public R<PropertyUserHouseBindResVo> bindHouse(@RequestBody @Validated PropertyUserHouseDto userHouseDto) {
        return R.data(baseService.bindHouse(userHouseDto));
    }

    /**
     * 发送验证码
     *
     * @param phone 手机号
     * @return
     */
    @GetMapping("/sendCode")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "发送验证码", notes = "传入手机号")
    public R<Map<String, String>> sendCode(@ApiParam(value = "手机号", required = true) @RequestParam String phone) {
        return R.data(baseService.sendCode(phone));
    }

    /**
     * 验证验证码是否正确
     *
     * @param verifyCodeDto 验证验证码传参
     * @return
     */
    @PostMapping("/verifyCode")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "验证验证码是否正确", notes = "传入手机号和验证码")
    public R<Boolean> verifyCode(@RequestBody @Validated PropertyVerifyCodeDto verifyCodeDto) {
        return R.data(baseService.verifyCode(verifyCodeDto));
    }

    /**
     * 用户房产列表(分页)
     * @param queryDto 企业入驻登记列表查询参数
     * @return 企业入驻登记列表Vo
     */
    @PostMapping("/getUserHouseList")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "用户房产列表(分页)", notes = "用户房产列表(分页)")
    public R<NestPage<PropertyUserHouseListVo>> getUserHouseList(@RequestBody PropertyUserHouseQueryDto queryDto) {
        return R.data(baseService.getUserHouseList(queryDto));
    }

    /**
     * 用户移除房间
     * @param id 主键ID
     * @return TRUE/FALSE
     */
    @DeleteMapping("/deleteUserHouse/{id}")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "用户移除房间", notes = "用户移除房间")
    public R<Boolean> deleteUserHouse(@ApiParam(name = "id", value = "主键ID", required = true) @PathVariable("id") Long id) {
        return R.data(baseService.deleteUserHouse(id));
    }

    /**
     * 业主添加/编辑住户
     * @param ownerResidentDto 业主添加/编辑住户Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/saveOrUpdateResident")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "业主添加/编辑住户", notes = "业主添加/编辑住户")
    public R<Boolean> saveOrUpdateResident(@RequestBody @Validated PropertyOwnerResidentDto ownerResidentDto) {
        return R.data(baseService.saveOrUpdateResident(ownerResidentDto));
    }

    /**
     * 业主移除住户
     * @param id 主键ID
     * @return TRUE/FALSE
     */
    @DeleteMapping("/removeResident/{id}")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "业主移除住户", notes = "业主移除住户")
    public R<Boolean> removeResident(@ApiParam(name = "id", value = "主键ID", required = true) @PathVariable("id") Long id) {
        return R.data(baseService.removeResident(id));
    }

    /**
     * 业主住户列表
     * @param queryDto 企业入驻登记列表查询参数
     * @return 企业入驻登记列表Vo
     */
    @PostMapping("/getResidentList")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "业主住户列表", notes = "业主住户列表")
    public R<NestPage<PropertyOwnerResidentListVo>> getResidentList(@RequestBody PropertyUserHouseQueryDto queryDto) {
        return R.data(baseService.getResidentList(queryDto));
    }

    /**
     * 获取用户房产园区列表
     * @param userDetailId 平台用户ID
     * @return 用户房产园区列表
     */
    @PostMapping("/getUserHouseParkList")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "获取用户房产园区列表", notes = "获取用户房产园区列表")
    public R<List<Long>> getUserHouseParkList(@ApiParam(value = "平台用户ID", required = true) @RequestParam Long userDetailId) {
        return R.data(baseService.getUserHouseParkList(userDetailId));
    }

}
