package com.gree.mall.manager.controller.common;


import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.beust.jcommander.Parameter;
import com.gree.mall.manager.annotation.ApiNotAuth;
import com.gree.mall.manager.annotation.ZfireList;
import com.gree.mall.manager.bean.common.AmityUrlVO;
import com.gree.mall.manager.bean.common.ImgCarouselManageBean;
import com.gree.mall.manager.enums.IsYesNoEnum;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.common.CompanyRecordLogic;
import com.gree.mall.manager.plus.entity.AmityUrl;
import com.gree.mall.manager.plus.entity.CompanyRecordManage;
import com.gree.mall.manager.plus.entity.ImgCarouselManage;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@Api(value = "轮播图API", tags ={"轮播图API"} )
@RequestMapping(value = "/record", produces = "application/json; charset=utf-8")
public class CompanyRecordController {

    @Autowired
    CompanyRecordLogic companyRecordLogic;

    @PostMapping("company/add")
    @ApiOperation(value = "新增公司备案信息")
    public ResponseHelper addRecordCompany(@RequestBody CompanyRecordManage companyRecordManage) {
        companyRecordLogic.addRecordCompany(companyRecordManage);
        return ResponseHelper.success();
    }

    @PostMapping("company/update")
    @ApiOperation(value = "修改")
    public ResponseHelper editRecordCompany(@RequestBody CompanyRecordManage companyRecordManage) {
        companyRecordLogic.editRecordCompany(companyRecordManage);
        return ResponseHelper.success();
    }

    @ApiNotAuth
    @GetMapping("company/list")
    @ApiOperation(value = "公司列表")
    public ResponseHelper<List<CompanyRecordManage>> companyRecordList() {
        List<CompanyRecordManage> companyRecordManage = companyRecordLogic.companyRecordList();
        return ResponseHelper.success(companyRecordManage);
    }

    @ApiNotAuth
    @GetMapping("company/detail")
    @ApiOperation(value = "查询")
    public ResponseHelper<CompanyRecordManage> getCompany(@RequestParam String id) {
        CompanyRecordManage imgCarouselManage = companyRecordLogic.getCompany(id);
        return ResponseHelper.success(imgCarouselManage);
    }

    @PostMapping("carousel/add")
    @ApiOperation(value = "新增轮播图信息")
    public ResponseHelper addImgCarousel(@RequestBody ImgCarouselManage imgCarouselManage) {
        companyRecordLogic.addImgCarousel(imgCarouselManage);
        return ResponseHelper.success();
    }

    @ApiNotAuth
    @GetMapping("list")
    @ApiOperation(value = "轮播图列表")
    public ResponseHelper<List<ImgCarouselManage>> list() {
        List<ImgCarouselManage> adminRoleIPage = companyRecordLogic.list();
        return ResponseHelper.success(adminRoleIPage);
    }

    @PostMapping("delete")
    @ApiOperation(value = "批量删除轮播图")
    public ResponseHelper delete(@RequestParam List<String> ids) {
        companyRecordLogic.delete(ids);
        return ResponseHelper.success();
    }

    @ApiNotAuth
    @GetMapping("detail")
    @ApiOperation(value = "查询")
    public ResponseHelper<ImgCarouselManage> get(@RequestParam String id) {
        ImgCarouselManage imgCarouselManage = companyRecordLogic.detail(id);
        return ResponseHelper.success(imgCarouselManage);
    }

    @PostMapping("update")
    @ApiOperation(value = "修改")
    public ResponseHelper update(@RequestBody ImgCarouselManageBean imgCarouselManage) {
        companyRecordLogic.update(imgCarouselManage);
        return ResponseHelper.success();
    }

    @PostMapping("updateImgStatus")
    @ApiOperation(value = "轮播图显示与隐藏")
    public ResponseHelper weatherShow(@RequestParam String id) {
        companyRecordLogic.updateStatus(id);
        return ResponseHelper.success();
    }


    @PostMapping("amity/add")
    @ApiOperation(value = "友情链接-新增")
    public ResponseHelper addAmity(@RequestBody AmityUrl amityUrl) {
        companyRecordLogic.addAmity(amityUrl);
        return ResponseHelper.success();
    }

    @PostMapping("amity/update")
    @ApiOperation(value = "友情链接-修改")
    public ResponseHelper updateAmity(@RequestBody AmityUrl amityUrl) {
        companyRecordLogic.updateAmity(amityUrl);
        return ResponseHelper.success();
    }

    @PostMapping("amity/delete")
    @ApiOperation(value = "友情链接-批量删除")
    public ResponseHelper deleteAmity(@RequestParam List<String> amityUrlIds) {
        companyRecordLogic.deleteAmity(amityUrlIds);
        return ResponseHelper.success();
    }

    @PostMapping("amity/status")
    @ApiOperation(value = "友情链接-状态 有效/无效")
    public ResponseHelper amityStatus(@RequestParam String amityUrlId, @ApiParam(required = true, value = "YES NO") @RequestParam IsYesNoEnum status) {
        companyRecordLogic.amityStatus(amityUrlId, status);
        return ResponseHelper.success();
    }

    @ApiNotAuth
    @ZfireList
    @PostMapping("amity/list")
    @ApiOperation(value = "友情链接-列表")
    public ResponseHelper<IPage<AmityUrlVO>> amityList(@RequestBody ZfireParamBean zfireParamBean) {
        IPage<AmityUrlVO> list = companyRecordLogic.amityList(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<AmityUrlVO>() {
        });
    }

    @ApiNotAuth
    @PostMapping("amity/list2")
    @ApiOperation(value = "友情链接-列表")
    public ResponseHelper<List<AmityUrl>> amityList() {
        List<AmityUrl> amityUrls = companyRecordLogic.list2();
        return ResponseHelper.success(amityUrls);
    }

}
