package com.ylx.project.controller;

import com.ylx.common.core.domain.R;
import com.ylx.project.domain.bookMerchant.dto.BookMerchantDTO;
import com.ylx.project.domain.bookMerchant.vo.BookProjectDetailVO;
import com.ylx.project.domain.vo.ProjectBaseVo;
import com.ylx.project.domain.vo.ProjectDetailVo;
import com.ylx.project.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/customer/project")
@Api(tags = {"客户端项目相关"})
@Slf4j
@PreAuthorize("@customerAuth.isCustomer()")
public class CustomerProjectController {

    @Resource
    private ProjectService projectService;

    @ApiOperation("客户端根据服务标签获取服务项目集合数据")
    @GetMapping("/categoryId/{categoryId}")
    public R<List<ProjectBaseVo>> getProjectTabList(@PathVariable("categoryId") Integer categoryId) {
        List<ProjectBaseVo> list = this.projectService.getProjectTabListByCategoryId(categoryId);
        return R.ok(list);
    }

    @ApiOperation("客户端获取服务项目集合数据,用于更多、同城搭子页面")
    @GetMapping("/list")
    public R<List<ProjectBaseVo>> listProjects() {
        List<ProjectBaseVo> list = this.projectService.listProjects();
        return R.ok(list);
    }

    @ApiOperation("客户端获取去预约项目详情")
    @PostMapping("/bookDetail")
    public R<BookProjectDetailVO> getBookingProjectDetail(@Validated @RequestBody BookMerchantDTO dto) {
        BookProjectDetailVO vo = this.projectService.getBookingProjectDetail(dto);
        return R.ok(vo);
    }

    @ApiOperation("客户端根据ID获取项目详情信息")
    @GetMapping("/detail/{id}")
    public R<ProjectDetailVo> getDetailById(@PathVariable("id") Long id) {
        return R.ok(this.projectService.getDetailsInfo(id));
    }
}
