package com.cool.store.controller.webc;

import com.cool.store.context.PartnerUserHolder;
import com.cool.store.request.visit.StoreVisitReservationCancelRequest;
import com.cool.store.request.visit.StoreVisitReservationCreateRequest;
import com.cool.store.request.visit.StoreVisitReservationMyQueryRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.visit.StoreVisitReservationService;
import com.cool.store.vo.PartnerUserInfoVO;
import com.cool.store.vo.visit.StoreVisitReservationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@Api(tags = "小程序-预约到店")
@RestController
@RequestMapping("/mini/storeVisitReservation")
@RequiredArgsConstructor
@Validated
public class MiniStoreVisitReservationController {

    private final StoreVisitReservationService storeVisitReservationService;

    @ApiOperation("新增预约")
    @PostMapping("/create")
    public ResponseResult<Long> create(@RequestBody @Validated StoreVisitReservationCreateRequest request) {
        return ResponseResult.success(storeVisitReservationService.create(request));
    }

    @ApiOperation("预约详情")
    @GetMapping("/detail")
    @ApiImplicitParam(name = "id", value = "预约ID", required = true, dataType = "Long", paramType = "query")
    public ResponseResult<StoreVisitReservationVO> detail(@NotNull(message = "预约ID不能为空") Long id) {
        return ResponseResult.success(storeVisitReservationService.detail(id));
    }

    @ApiOperation("我的预约")
    @PostMapping("/myList")
    public ResponseResult<List<StoreVisitReservationVO>> myList(@RequestBody @Validated StoreVisitReservationMyQueryRequest request) {
        PartnerUserInfoVO user = PartnerUserHolder.getUser();
        return ResponseResult.success(storeVisitReservationService.myReservations(user.getMobile(),request.getStatus()));
    }

    @ApiOperation("取消预约")
    @PostMapping("/cancel")
    public ResponseResult<Boolean> cancel(@RequestBody @Validated StoreVisitReservationCancelRequest request) {
        return ResponseResult.success(storeVisitReservationService.cancel(request));
    }
}
