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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yuchen.saas.park.api.dto.building.*;
import com.yuchen.saas.park.api.entity.building.PmgBatBuildingReservation;
import com.yuchen.saas.park.api.vo.building.PmgBatBuildingReservationPageVO;
import com.yuchen.saas.park.service.service.building.IPmgBatBuildingReservationService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *
 * 预约看房订单 相关接口
 *
 *
 * @author yuanzhelin
 * @since 2024-10-17
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/pmgBatBuildingReservation")
public class PmgBatBuildingReservationController {

    @Resource
    private IPmgBatBuildingReservationService pmgBatBuildingReservationService;
    /**
     * 分页查询
     * @tag pauly-lyz
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public R<IPage<PmgBatBuildingReservationPageVO>> page(@RequestBody PmgBatBuildingReservationQueryDto dto) {
        return R.data(pmgBatBuildingReservationService.pages(dto));
    }
    /**
     * 看房预约变更
     * @tag pauly-lyz
     */
    @PutMapping("/change")
    @ApiOperation(value = "看房预约变更")
    public R change(@RequestBody PmgBatBuildingReservationChangeDto dto) {
        return R.data(pmgBatBuildingReservationService.change(dto));
    }
    /**
     * 确定客户已到访
     * @tag pauly-lyz
     */
    @PutMapping("/confirmVisit")
    @ApiOperation(value = "确定客户已到访")
    public R confirmVisit(@RequestBody PmgBatBuildingReservationConfirmVisitDto dto) {
        return R.data(pmgBatBuildingReservationService.confirmVisit(dto));
    }
    /**
     * 取消客户预约
     * @tag pauly-lyz
     */
    @PutMapping("/cancel")
    @ApiOperation(value = "取消客户预约")
    public R cancel(@RequestBody PmgBatBuildingReservationCancelDto dto) {
        return R.data(pmgBatBuildingReservationService.cancel(dto));
    }

    //---------------------------------小程序用--------------------------------------
    @PostMapping("/app/save")
    @ApiOperation(value = "新增预约")
    public R save(@RequestBody PmgBatBuildingReservationAddDto dto) {
        PmgBatBuildingReservation pmgBatBuildingReservation = new PmgBatBuildingReservation();
        BeanUtils.copyProperties(dto, pmgBatBuildingReservation);
        return R.data(pmgBatBuildingReservationService.save(pmgBatBuildingReservation));
    }

    @GetMapping("/app/detail/{id}")
    @ApiOperation(value = "预约详情")
    public R<PmgBatBuildingReservation> detail(@PathVariable Long id) {
        return R.data(pmgBatBuildingReservationService.getById(id));
    }

    @PostMapping("/app/confirm")
    @ApiOperation(value = "预约确认")
    public R confirmVisitApp(@RequestBody PmgBatBuildingReservationConfirmVisitAppDto dto) {
        return R.data(pmgBatBuildingReservationService.confirmVisitApp(dto));
    }
    @GetMapping("/app/cancel")
    @ApiOperation(value = "预约取消")
    public R cancelVisitApp(@RequestParam Long id) {
        return R.data(pmgBatBuildingReservationService.cancel(id));
    }
}
