package com.amms.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.amms.domain.vo.Result;
import com.amms.domain.ReservationVisitor;
import com.amms.service.IReservationVisitorService;

import java.util.List;

/**
 * 游客预约明细Controller
 */
@RestController
@RequestMapping("/reservationVisitor")
public class ReservationVisitorController {

    @Autowired
    private IReservationVisitorService reservationVisitorService;

    /**
     * 查询游客预约明细列表
     */
    @GetMapping("/list")
    public PageInfo list(ReservationVisitor reservationVisitor, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ReservationVisitor> reservationVisitors = reservationVisitorService.selectReservationVisitorList(reservationVisitor);
        return new PageInfo(reservationVisitors);
    }

    /**
     * 查询全部游客预约明细列表
     */
    @GetMapping("/listAll")
    public List<ReservationVisitor> listAll(ReservationVisitor reservationVisitor) {
        return reservationVisitorService.selectReservationVisitorList(reservationVisitor);
    }

    /**
     * 获取游客预约明细详细信息
     */
    @GetMapping(value = "/info/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.success(reservationVisitorService.selectReservationVisitorById(id));
    }

    /**
     * 新增游客预约明细
     */
    @PostMapping("/add")
    public Result add(@RequestBody ReservationVisitor reservationVisitor) {
        return reservationVisitorService.insertReservationVisitor(reservationVisitor) > 0 ? Result.success("新增成功") : Result.error("新增失败");
    }

    /**
     * 修改游客预约明细
     */
    @PutMapping
    public Result update(@RequestBody ReservationVisitor reservationVisitor) {
        return reservationVisitorService.updateReservationVisitor(reservationVisitor) > 0 ? Result.success("修改成功") : Result.error("修改失败");
    }

    /**
     * 删除游客预约明细
     */
	@DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        return reservationVisitorService.deleteReservationVisitorById(id) > 0 ? Result.success("删除成功") : Result.error("删除失败");
    }
}
