package com.corewing.app.modules.app;

import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.corewing.app.common.Result;
import com.corewing.app.common.annotation.CommonLog;
import com.corewing.app.dto.AppModel.*;
import com.corewing.app.entity.AppModel;
import com.corewing.app.entity.AppModelCategory;
import com.corewing.app.service.AppModelCategoryService;
import com.corewing.app.service.AppModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 模型
 */
@RestController
@RequestMapping("/model")
@Validated
@Api(tags = "模型接口")
public class AppModelController {

    @Resource
    private AppModelService appModelService;

    @Resource
    private AppModelCategoryService appModelCategoryService;

    /**
     * 获取模型分页
     * @param modelPageRequest
     * @return
     */
    @CommonLog("模型数据分页")
    @ApiOperation("模型数据分页")
    @GetMapping("/page")
    public Result<Page<AppModel>> page(ModelPageRequest modelPageRequest) {
        return Result.success(appModelService.page(modelPageRequest));
    }

    /**
     * 获取模型集合
     * @param modelListRequest
     * @return
     */
    @CommonLog("模型数据集合")
    @ApiOperation("模型数据集合")
    @GetMapping("/list")
    public Result<List<AppModel>> list(ModelListRequest modelListRequest) {
        return Result.success(appModelService.list(modelListRequest));
    }


    /**
     * 获取模型分类分页
     * @param modelCategoryPageRequest
     * @return
     */
    @CommonLog("模型分类数据分页")
    @ApiOperation("模型分类数据分页")
    @GetMapping("/category/page")
    public Result<Page<AppModelCategory>> categoryPage(ModelCategoryPageRequest modelCategoryPageRequest) {
        return Result.success(appModelCategoryService.page(modelCategoryPageRequest));
    }

    /**
     * 获取模型分类集合
     * @param modelCategoryListRequest
     * @return
     */
    @CommonLog("模型分类数据集合")
    @ApiOperation("模型分类数据集合")
    @GetMapping("/category/list")
    public Result<List<AppModelCategory>> categoryList(ModelCategoryListRequest modelCategoryListRequest) {
        return Result.success(appModelCategoryService.list(modelCategoryListRequest));
    }

    /**
     * 获取模型分类树形集合
     * @param modelCategoryListRequest
     * @return
     */
    @CommonLog("模型分类树形集合")
    @ApiOperation("模型分类树形集合")
    @GetMapping("/category/tree")
    public Result<List<Tree<String>>> categoryTree(ModelCategoryListRequest modelCategoryListRequest) {
        return Result.success(appModelCategoryService.tree(modelCategoryListRequest));
    }

    /**
     * 模型收藏
     * @param modelFavoriteRequest
     * @return
     */
    @CommonLog("收藏模型")
    @ApiOperation("收藏模型")
    @PostMapping("/favorite")
    public Result<String> favorite(@RequestBody @Valid ModelFavoriteRequest modelFavoriteRequest) {
        return Result.isBool(appModelService.favorite(modelFavoriteRequest));
    }

    /**
     * 增加模型下载记录
     * @param modelDownloadRequest
     * @return
     */
    @CommonLog("增加模型下载记录")
    @ApiOperation("增加模型下载记录")
    @PostMapping("/download")
    public Result<String> download(@RequestBody @Valid ModelDownloadRequest modelDownloadRequest) {
        return Result.isBool(appModelService.download(modelDownloadRequest));
    }

    /**
     * 点赞模型
     * @param modelLikeRequest
     * @return
     */
    @CommonLog("点赞模型")
    @ApiOperation("点赞模型")
    @PostMapping("/like")
    public Result<String> like(@RequestBody @Valid ModelLikeRequest modelLikeRequest) {
        return Result.isBool(appModelService.like(modelLikeRequest));
    }

    /**
     * 模型详情
     * @return
     */
    @CommonLog("模型详情")
    @ApiOperation("模型详情")
    @GetMapping("/detail/{modelId}")
    public Result<AppModel> detail(@PathVariable String modelId) {
        return Result.success(appModelService.detail(modelId));
    }

    /**
     * 创建模型
     * @param modelCreateRequest
     * @return
     */
    @CommonLog("创建模型")
    @ApiOperation("创建模型")
    @PostMapping("/create")
    public Result<String> create(@Valid ModelCreateRequest modelCreateRequest) {
        return Result.isBool(appModelService.create(modelCreateRequest));
    }

    /**
     * 提交模型审核
     * @param modelIdRequest
     * @return
     */
    @CommonLog("提交模型审核")
    @ApiOperation("提交模型审核")
    @PostMapping("/audit")
    public Result<String> audit(@RequestBody @Valid ModelIdRequest modelIdRequest) {
        return Result.isBool(appModelService.audit(modelIdRequest));
    }

    /**
     * 获取收藏列表
     * @param modelFavoriteListRequest
     * @return
     */
    @CommonLog("收藏模型列表")
    @ApiOperation("收藏模型列表")
    @GetMapping("/favorite/list")
    public Result<List<AppModel>> favoriteList(ModelFavoriteListRequest modelFavoriteListRequest) {
        return Result.success(appModelService.favoriteList(modelFavoriteListRequest));
    }

    /**
     * 获取收藏分页列表
     * @param modelFavoritePageRequest
     * @return
     */
    @CommonLog("收藏模型分页列表分页")
    @ApiOperation("收藏模型分页列表分页")
    @GetMapping("/favorite/page")
    public Result<Page<AppModel>> favoritePage(ModelFavoritePageRequest modelFavoritePageRequest) {
        return Result.success(appModelService.favoritePage(modelFavoritePageRequest));
    }

    /**
     * 模型下架
     * @param modelIdRequest
     * @return
     */
    @CommonLog("模型下架")
    @ApiOperation("模型下架")
    @PostMapping("/delisted")
    public Result<String> delisted(@RequestBody @Valid ModelIdRequest modelIdRequest) {
        return Result.isBool(appModelService.delisted(modelIdRequest));
    }


    /**
     * 模型下载记录列表
     * @param modelDownloadLogListRequest
     * @return
     */
    @CommonLog("模型下载记录列表")
    @ApiOperation("模型下载记录列表")
    @GetMapping("/download_log/list")
    public Result<List<AppModel>> downloadLogList(ModelDownloadLogListRequest modelDownloadLogListRequest) {
        return Result.success(appModelService.downloadLogList(modelDownloadLogListRequest));
    }

    /**
     * 模型下载记录分页列表
     * @param modelDownloadLogPageRequest
     * @return
     */
    @CommonLog("模型下载记录分页列表分页")
    @ApiOperation("模型下载记录分页列表分页")
    @GetMapping("/download_log/page")
    public Result<Page<AppModel>> downloadLogPage(ModelDownloadLogPageRequest modelDownloadLogPageRequest) {
        return Result.success(appModelService.downloadLogPage(modelDownloadLogPageRequest));
    }

    /**
     * 删除模型
     * @return
     */
    @CommonLog("删除模型")
    @ApiOperation("删除模型")
    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@PathVariable String id) {
        return Result.isBool(appModelService.delete(id));
    }

}
