package shop.alien.storeplatform.controller;

import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.StoreMenu;
import shop.alien.entity.store.vo.StoreMenuVo;
import shop.alien.storeplatform.service.StorePlatformMenuService;

import java.util.List;

/**
 * 二期-门店菜单Controller
 *
 * @author ssk
 * @since 2024-12-05
 */
@Slf4j
@Api(tags = {"商户平台-门店菜单"})
@ApiSort(4)
@CrossOrigin
@RestController
@RequestMapping("/menu")
@RequiredArgsConstructor
public class StorePlatformMenuController {

    private final StorePlatformMenuService storeMenuService;

    @ApiOperation("获取门店菜单")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "dishType", value = "菜品类型, 0:菜单, 1:推荐", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "phoneId", value = "消息标识", dataType = "Integer", paramType = "query")
    })
    @GetMapping("/getMenuByStoreId")
    public R<List<StoreMenuVo>> getMenuByStoreId(Integer storeId, Integer dishType, String phoneId) {
        log.info("StoreRecommendController.getByStoreId?id={}&dishType={}&phoneId={}", storeId, dishType, phoneId);
        return R.data(storeMenuService.getStoreMenu(storeId, dishType, phoneId));
    }

    @ApiOperation("新增或修改门店菜单")
    @ApiOperationSupport(order = 2)
    @PostMapping("/saveOrUpdate")
    public R<String> saveOrUpdate(@RequestBody StoreMenuVo storeMenuVo) {
        log.info("StoreRecommendController.saveOrUpdateMenu?storeMenu={}", storeMenuVo);
        return storeMenuService.saveOrUpdateMenus(storeMenuVo);
    }

    @ApiOperation(value = "删除门店菜单")
    @ApiOperationSupport(order = 3)
    @GetMapping("/delete")
    public R<String> delete(@RequestParam(value = "ids") List<Integer> ids, @RequestParam(value = "dishType") int dishType) {
        log.info("StoreRecommendController.delete?ids={}", ids);
        return storeMenuService.deleteMenu(ids, dishType);
    }

    @ApiOperation("获取菜品详情")
    @ApiOperationSupport(order = 4)
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "菜品id", dataType = "Integer", paramType = "query")})
    @GetMapping("/getMenuInfo")
    public R<StoreMenuVo> getMenuInfo(Integer id) {
        log.info("StoreRecommendController.getMenuInfo?id={}", id);
        return R.data(storeMenuService.getMenuInfo(id));
    }

    @ApiOperation("菜品排序")
    @ApiOperationSupport(order = 5)
    @PostMapping("/getSortMenuInfo")
    public R<Boolean> getSortMenuInfo(@RequestBody StoreMenuVo storeMenuVo) {
        log.info("StoreRecommendController.getSortMenuInfo?storeMenuVo={}", storeMenuVo);
        Boolean flag = false;
        flag = storeMenuService.getSortMenuInfo(storeMenuVo);
        if (flag) {
            return R.success("已更新排序");
        } else {
            return R.fail("排序失败");
        }
    }

    @ApiOperation("保存菜品排序")
    @ApiOperationSupport(order = 6)
    @PostMapping("/saveMenuSort")
    public R<Boolean> saveMenuSort(@RequestBody List<StoreMenu> storeMenuList) {
        log.info("StoreRecommendController.saveMenuSort?storeMenuList={}", storeMenuList);
        Boolean flag = false;
        flag = storeMenuService.saveMenuSort(storeMenuList);
        if (flag) {
            return R.success("已更新排序");
        } else {
            return R.fail("排序失败");
        }
    }

    @ApiOperation("获取门店菜品推荐数量")
    @ApiOperationSupport(order = 7)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getMenuCountByStoreId")
    public R<StoreMenuVo> getMenuCountByStoreId(Integer storeId) {
        log.info("StoreRecommendController.getMenuCountByStoreId?id={}", storeId);
        return R.data(storeMenuService.getMenuCountByStoreId(storeId));
    }

    @ApiOperation("获取用户对该菜品是否点赞")
    @ApiOperationSupport(order = 8)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "menuId", value = "菜品id", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getMenuLikeStatus")
    public R<Boolean> getMenuLikeStatus(String userId, Integer menuId) {
        log.info("StoreRecommendController.getMenuLikeStatus?userId={}&menuId={}", userId, menuId);
        return R.data(storeMenuService.getMenuLikeStatus(userId, menuId));
    }
}
