package com.wzj.soopin.content.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.content.convert.ArticleConvert;
import com.wzj.soopin.content.domain.bo.ArticleBO;
import com.wzj.soopin.content.domain.po.Article;
import com.wzj.soopin.content.domain.vo.ArticleVO;
import com.wzj.soopin.content.service.IArticleCategoryService;
import com.wzj.soopin.content.service.IArticleService;
import com.wzj.soopin.member.convert.TenantForbiddenConvert;
import com.wzj.soopin.member.domain.bo.TenantForbiddenBO;
import com.wzj.soopin.member.domain.po.TenantForbidden;
import com.wzj.soopin.member.domain.vo.TenantForbiddenVO;
import com.wzj.soopin.member.service.ITenantForbiddenService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户封禁
 */
@Tag(name = "内容管理")
@RestController
@RequestMapping("/cms/article")
@RequiredArgsConstructor
public class ArticleController {

    private final IArticleService service;
    private final ArticleConvert convert;

    @Tag(name = "查询列表")
    @PostMapping("/page")
    public R<IPage<ArticleVO>> page(@RequestBody ArticleBO bo, @RequestBody Page page) {
        Page<Article> pages = service.page(page, bo.toWrapper());
        return R.ok(convert.toVO(pages));
    }

    @Tag(name = "查询列表")
    @PostMapping("/list")
    public R< List<ArticleVO>> list(@RequestBody ArticleBO bo, @RequestBody Page page) {
        List<ArticleVO> articleList = service.selectVoList( bo.toWrapper());
        return R.ok(articleList);
    }

    @Tag(name = "新增")
    @Log(title = "新增 ", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody ArticleBO bo) {
        return R.ok(service.save(convert.toPo(bo)));
    }

    @Tag(name = "详情")
    @GetMapping(value = "/{id}")
    public R<ArticleVO> getInfo(@PathVariable("id") Long id) {
        return R.ok(convert.toVO(service.getById(id)));
    }

    @Tag(name = ("处理"))
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R update(@RequestBody ArticleBO bo) {
        service.saveOrUpdate(convert.toPo(bo));
        return R.ok();
    }


    @Tag(name = "删除")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Object> remove(@PathVariable Long id) {
        return R.ok(service.removeById(id));
    }


    @Tag(name = "轮播列表")
    @PostMapping("/carousel")
    public R< List<ArticleVO>> carousel(@RequestBody ArticleBO bo, @RequestBody Page page) {
        bo.setType(1);//轮播图
        List<ArticleVO> articleList = service.selectVoList( bo.toWrapper());
        return R.ok(articleList);
    }

}
