package com.liquidnet.service.goblin.controller;

import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinFrontArtistTopicDetailVo;
import com.liquidnet.service.goblin.dto.vo.GoblinFrontArtistTopicHomeVo;
import com.liquidnet.service.goblin.dto.vo.GoblinFrontArtistTopicListPageVo;
import com.liquidnet.service.goblin.service.impl.GoblinFrontArtistTopicServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;

/**
 * C 端-艺人专题（周边商城）
 */
@Api(tags = "C端艺人专题")
@Slf4j
@Validated
@RestController
@RequestMapping("front/artistTopic")
public class GoblinFrontArtistTopicController {

    @Autowired
    private GoblinFrontArtistTopicServiceImpl artistTopicService;

    @GetMapping("home")
    @ApiOperation("首页入口（推荐位专题+更多）")
    public ResponseDto<GoblinFrontArtistTopicHomeVo> home() {
        return artistTopicService.home();
    }

    @GetMapping("list")
    @ApiOperation("专题列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "int", required = true),
    })
    public ResponseDto<GoblinFrontArtistTopicListPageVo> list(
            @Min(1) @RequestParam(defaultValue = "1") int page,
            @Min(1) @RequestParam(defaultValue = "20") int size) {
        return artistTopicService.list(page, size);
    }

    @GetMapping("detail")
    @ApiOperation("专题详情（商品支持 default/price 排序）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "topicId", value = "专题ID", dataType = "String", required = true),
            @ApiImplicitParam(name = "sortType", value = "商品排序 default-默认排序 price-价格排序", dataType = "String", allowableValues = "default,price"),
            @ApiImplicitParam(name = "sortOrder", value = "价格排序方向 asc-升序 desc-降序（sortType=price时生效）", dataType = "String", allowableValues = "asc,desc"),
    })
    public ResponseDto<GoblinFrontArtistTopicDetailVo> detail(
            @NotBlank(message = "专题ID不能为空") @RequestParam String topicId,
            @RequestParam(required = false, defaultValue = "default") String sortType,
            @RequestParam(required = false, defaultValue = "asc") String sortOrder) {
        return artistTopicService.detail(topicId, sortType, sortOrder);
    }
}
