package shop.alien.dining.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiSort;
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.LifeCollect;
import shop.alien.dining.service.DiningCollectService;

/**
 * 点餐模块-收藏控制器（Feign 调 store，供小程序使用）
 *
 * @author ssk
 * @version 1.0
 * @date 2025/01/XX
 */
@Slf4j
@Api(tags = {"微信点餐-收藏(用户端)"})
@ApiSort(4)
@CrossOrigin
@RestController
@RequestMapping("/dining/collect")
@RequiredArgsConstructor
public class DiningCollectController {

    private final DiningCollectService diningCollectService;

    /**
     * 添加收藏
     */
    @ApiOperation(value = "添加收藏", notes = "添加收藏，支持收藏店铺、商品等")
    @ApiOperationSupport(order = 1)
    @PostMapping("/addCollect")
    public R<Boolean> addCollect(@ApiParam(value = "收藏对象", required = true) @RequestBody LifeCollect lifeCollect) {
        log.info("DiningCollectController.addCollect?lifeCollect={}", lifeCollect);
        try {
            return diningCollectService.addCollect(lifeCollect);
        } catch (Exception e) {
            log.error("添加收藏失败: {}", e.getMessage(), e);
            return R.fail("添加收藏失败: " + e.getMessage());
        }
    }
}
