package com.liquidnet.service.goblin.controller.manage;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.*;
import com.liquidnet.service.goblin.dto.manage.vo.*;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtArtistService;
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.*;

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

/**
 * 商家端-艺人关联申请 / 艺人专题
 * <p>店铺由登录 UID 解析，对齐售后单管理</p>
 */
@ApiSupport(order = 149020)
@Api(tags = "艺人管理")
@Slf4j
@Validated
@RestController
@RequestMapping("store/mgt/artist")
public class GoblinStoreMgtArtistController {

    @Autowired
    private IGoblinStoreMgtArtistService artistService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("搜索可申请艺人")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "艺人名称关键词", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "int", required = true),
    })
    @GetMapping("list")
    public ResponseDto<PagedResult<GoblinStoreMgtArtistSearchItemVo>> searchArtist(
            @RequestParam(required = false) String keyword,
            @Min(1) @RequestParam(defaultValue = "1") int page,
            @Min(1) @RequestParam(defaultValue = "20") int size) {
        return artistService.searchArtist(keyword, page, size);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("提交艺人关联申请")
    @PostMapping("apply/submit")
    public ResponseDto<String> submitApply(
            @Valid @RequestBody GoblinStoreMgtArtistApplySubmitParams params) {
        return artistService.submitApply(params);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("艺人关联申请列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "状态 0待审核 1已通过 2已拒绝 3已撤销", dataType = "int"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "int", required = true),
    })
    @GetMapping("apply/list")
    public ResponseDto<PagedResult<GoblinStoreMgtArtistApplyListItemVo>> applyList(
            @RequestParam(required = false) Integer status,
            @Min(1) @RequestParam(defaultValue = "1") int page,
            @Min(1) @RequestParam(defaultValue = "20") int size) {
        return artistService.applyList(status, page, size);
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("撤销艺人关联申请")
    @PostMapping("apply/revoke")
    public ResponseDto<Void> revokeApply(
            @Valid @RequestBody GoblinStoreMgtArtistApplyRevokeParams params) {
        return artistService.revokeApply(params);
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("本店已授权艺人列表")
    @GetMapping("auth/list")
    public ResponseDto<GoblinStoreMgtArtistAuthListVo> authList() {
        return artistService.authList();
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation("艺人专题列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "状态 0待上架 1已上架 2已下架", dataType = "int"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "int", required = true),
    })
    @GetMapping("topic/list")
    public ResponseDto<GoblinStoreMgtArtistTopicPageVo> topicList(
            @RequestParam(required = false) Integer status,
            @Min(1) @RequestParam(defaultValue = "1") int page,
            @Min(1) @RequestParam(defaultValue = "20") int size) {
        return artistService.topicList(status, page, size);
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation("艺人专题详情")
    @GetMapping("topic/detail")
    public ResponseDto<GoblinStoreMgtArtistTopicDetailVo> topicDetail(
            @NotBlank(message = "专题ID不能为空") @RequestParam String topicId) {
        return artistService.topicDetail(topicId);
    }

    @ApiOperationSupport(order = 8)
    @ApiOperation("创建艺人专题")
    @PostMapping("topic/create")
    public ResponseDto<String> topicCreate(
            @Valid @RequestBody GoblinStoreMgtArtistTopicCreateParams params) {
        return artistService.topicCreate(params);
    }

    @ApiOperationSupport(order = 9)
    @ApiOperation("编辑艺人专题")
    @PostMapping("topic/update")
    public ResponseDto<Void> topicUpdate(
            @Valid @RequestBody GoblinStoreMgtArtistTopicUpdateParams params) {
        return artistService.topicUpdate(params);
    }

    @ApiOperationSupport(order = 10)
    @ApiOperation("删除艺人专题")
    @PostMapping("topic/delete")
    public ResponseDto<Void> topicDelete(
            @Valid @RequestBody GoblinStoreMgtArtistTopicDeleteParams params) {
        return artistService.topicDelete(params);
    }

    @ApiOperationSupport(order = 11)
    @ApiOperation("艺人专题上下架")
    @PostMapping("topic/status")
    public ResponseDto<Void> topicStatus(
            @Valid @RequestBody GoblinStoreMgtArtistTopicStatusParams params) {
        return artistService.topicStatus(params);
    }

    @ApiOperationSupport(order = 12)
    @ApiOperation("搜索本店可添加商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "商品名称关键词", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "int", required = true),
    })
    @GetMapping("topic/searchGoods")
    public ResponseDto<PagedResult<GoblinStoreMgtArtistTopicGoodsSearchItemVo>> searchGoods(
            @RequestParam(required = false) String keyword,
            @Min(1) @RequestParam(defaultValue = "1") int page,
            @Min(1) @RequestParam(defaultValue = "20") int size) {
        return artistService.searchGoods(keyword, page, size);
    }
}
