package shop.alien.storeplatform.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
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.StoreOfficialAlbum;
import shop.alien.entity.store.vo.StoreOfficialAlbumVo;
import shop.alien.storeplatform.service.StorePlatformOfficialAlbumService;

import java.util.List;

/**
 * 官方相册前端控制器
 *
 * @author zhangchen
 * @since 2025-07-16
 */
@Slf4j
@Api(tags = {"商户平台-官方相册"})
@ApiSort(1)
@CrossOrigin
@RestController
@RequestMapping("/storePlatformOfficial")
@RequiredArgsConstructor
public class StorePlatformOfficialAlbumController {
    private final StorePlatformOfficialAlbumService storeOfficialAlbumService;

    @ApiOperation("创建/更新官方相册")
    @ApiOperationSupport(order = 1)
    @PostMapping("/createOrUpdateOfficialAlbum")
    public R<StoreOfficialAlbum> createOrUpdateOfficialAlbum(@RequestBody StoreOfficialAlbum storeOfficialAlbum) {
        log.info("StoreOfficialAlbumController.createOfficialAlbum?storeOfficialAlbum={}", storeOfficialAlbum);
        StoreOfficialAlbum storeOfficial = storeOfficialAlbumService.createOrUpdateOfficialAlbum(storeOfficialAlbum);
        return R.data(storeOfficial);
    }

    @ApiOperation("获取官方相册列表")
    @ApiOperationSupport(order = 2)
    @GetMapping("/getOfficialAlbumList")
    public R<List<StoreOfficialAlbumVo>> getOfficialAlbumList(String storeId) {
        log.info("StoreOfficialAlbumController.getOfficialAlbumList");
        List<StoreOfficialAlbumVo> storeOfficialAlbumList = storeOfficialAlbumService.getOfficialAlbumList(storeId);
        return R.data(storeOfficialAlbumList);
    }

    @ApiOperation("删除官方相册")
    @ApiOperationSupport(order = 3)
    @PostMapping("/deleteOfficialAlbum")
    public  R<Boolean> deleteOfficialAlbum(@RequestBody List<StoreOfficialAlbum> storeOfficialAlbumList) {
        log.info("StoreOfficialAlbumController.deleteOfficialAlbum");
        int result = storeOfficialAlbumService.deleteOfficialAlbum(storeOfficialAlbumList);
        if (result > 0) {
            return R.data(true);
        }
        return R.fail("失败");
    }
}
