package com.lesingle.modules.pub.controller;

import com.lesingle.common.result.PageResult;
import com.lesingle.common.result.Result;
import com.lesingle.modules.pub.service.PublicGalleryService;
import com.lesingle.security.annotation.Public;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "作品广场")
@RestController
@RequiredArgsConstructor
public class PublicGalleryController {

    private final PublicGalleryService publicGalleryService;

    @Public
    @GetMapping("/public/gallery")
    @Operation(summary = "广场作品列表")
    public Result<PageResult<Map<String, Object>>> getGalleryList(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) Long tagId,
            @RequestParam(required = false) String category,
            @RequestParam(required = false, defaultValue = "latest") String sortBy,
            @RequestParam(required = false) String keyword) {
        return Result.success(publicGalleryService.getGalleryList(page, pageSize, tagId, category, sortBy, keyword));
    }

    @Public
    @GetMapping("/public/gallery/recommended")
    @Operation(summary = "推荐作品")
    public Result<List<Map<String, Object>>> getRecommended() {
        return Result.success(publicGalleryService.getRecommended());
    }

    @Public
    @GetMapping("/public/gallery/{id}")
    @Operation(summary = "广场作品详情")
    public Result<Map<String, Object>> getGalleryDetail(@PathVariable Long id) {
        return Result.success(publicGalleryService.getGalleryDetail(id));
    }

    @Public
    @GetMapping("/public/users/{id}/works")
    @Operation(summary = "用户公开作品")
    public Result<PageResult<Map<String, Object>>> getUserPublicWorks(
            @PathVariable Long id,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize) {
        return Result.success(publicGalleryService.getUserPublicWorks(id, page, pageSize));
    }
}
