package org.dromara.ai.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.ai.domain.bo.AiPaintingFavoriteBo;
import org.dromara.ai.domain.vo.AiPaintingFavoriteVo;
import org.dromara.ai.service.AiPaintingFavoriteService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * AI绘画作品收藏管理
 *
 * @author pengles
 */
@Tag(name = "管理端-AI绘画作品收藏管理", description = "AI绘画作品收藏管理接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ai/painting/favorite")
public class AdminAiPaintingFavoriteController extends BaseController {

    private final AiPaintingFavoriteService aiPaintingFavoriteService;

    /**
     * 查询AI绘画作品收藏列表
     */
    @Operation(summary = "查询AI绘画作品收藏列表", description = "分页查询AI绘画作品收藏列表，支持多条件搜索")
    @SaCheckPermission("ai:painting:favorite:list")
    @GetMapping("/list")
    public TableDataInfo<AiPaintingFavoriteVo> list(@Parameter(description = "收藏查询条件") AiPaintingFavoriteBo bo,
                                                      @Parameter(description = "分页参数") PageQuery pageQuery) {
        return aiPaintingFavoriteService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出AI绘画作品收藏列表
     */
    @Operation(summary = "导出AI绘画作品收藏列表", description = "导出AI绘画作品收藏到Excel")
    @SaCheckPermission("ai:painting:favorite:export")
    @Log(title = "AI绘画作品收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Parameter(description = "收藏查询条件") AiPaintingFavoriteBo bo,
                       @Parameter(description = "响应对象") HttpServletResponse response) {
        List<AiPaintingFavoriteVo> list = aiPaintingFavoriteService.queryList(bo);
        ExcelUtil.exportExcel(list, "AI绘画作品收藏", AiPaintingFavoriteVo.class, response);
    }

    /**
     * 获取AI绘画作品收藏详细信息
     */
    @Operation(summary = "获取AI绘画作品收藏详情", description = "根据收藏ID获取详细信息")
    @SaCheckPermission("ai:painting:favorite:query")
    @GetMapping("/{id}")
    public R<AiPaintingFavoriteVo> getInfo(@Parameter(description = "收藏ID", required = true)
                                            @NotNull(message = "主键不能为空")
                                            @PathVariable Long id) {
        return R.ok(aiPaintingFavoriteService.queryById(id));
    }

    /**
     * 批量删除AI绘画作品收藏
     */
    @Operation(summary = "批量删除AI绘画作品收藏", description = "根据ID数组批量删除AI绘画作品收藏")
    @SaCheckPermission("ai:painting:favorite:remove")
    @Log(title = "AI绘画作品收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@Parameter(description = "收藏ID数组", required = true)
                           @NotNull(message = "主键不能为空")
                           @PathVariable Long[] ids) {
        return toAjax(aiPaintingFavoriteService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

}
