package com.wgb.system.service.controller;

import com.alibaba.fastjson.JSON;
import com.data.model.restful.response.InternalResponse;
import com.wgb.system.service.domain.model.SysExhibition;
import com.wgb.system.service.domain.request.SysExhibitionList;
import com.wgb.system.service.domain.response.LayuiTableResponse;
import com.wgb.system.service.service.SysExhibitionService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/sysExhibition")
@RestController
public class SysExhibitionController {

    private final SysExhibitionService sysExhibitionService;

    public SysExhibitionController(SysExhibitionService sysExhibitionService) {
        this.sysExhibitionService = sysExhibitionService;
    }

    @ApiOperation(value = "/获取轮播图List", response = SysExhibition.class)
    @ResponseBody
    @RequestMapping(value = "/list",method = {RequestMethod.POST})
    public LayuiTableResponse getList(@RequestBody SysExhibitionList sysExhibitionList){
        log.info("Start to execute /sysExhibition/list with, Param={}", sysExhibitionList);
        LayuiTableResponse response= sysExhibitionService.getList(sysExhibitionList);
        log.info("Return object for /sysExhibition/list is result={}", JSON.toJSON(response));
        return response;
    }


    @ApiOperation(value = "/新增系统轮播图", response = SysExhibition.class)
    @ResponseBody
    @RequestMapping(value = "/insertOrUpdata",method = {RequestMethod.POST})
    public InternalResponse insertOrUpdata(@RequestBody SysExhibition sysExhibition)throws Exception{
        log.info("Start to execute /sysExhibition/insertOrUpdata with, Param={}", sysExhibition);
        sysExhibitionService.insertOrUpdata(sysExhibition);
        log.info("Return object for /sysExhibition/insertOrUpdata is result={}", "success");
        return InternalResponse.success();
    }

    @ApiOperation(value = "/获取APP展示时的轮播图", response = SysExhibition.class)
    @ResponseBody
    @RequestMapping(value = "/getSysExhibitionList",method = {RequestMethod.POST})
    public InternalResponse getSysExhibitionList(@RequestBody SysExhibitionList sysExhibitionList){
        log.info("Start to execute /sysExhibition/getSysExhibitionList with, Param={}", sysExhibitionList);
        List<SysExhibition> list= sysExhibitionService.getSysExhibitionList(sysExhibitionList);
        log.info("Return object for /sysExhibition/getSysExhibitionList is result={}", JSON.toJSON(list));
        return InternalResponse.success().withBody(list);
    }

    @ApiOperation(value = "/修改轮播图片状态", response = InternalResponse.class)
    @ResponseBody
    @RequestMapping(value = "/updateByState", method = {RequestMethod.GET})
    public InternalResponse updateByState(@RequestParam(value = "id", required = true) Long id, @RequestParam(value = "state", required = true) Integer state) {
        log.info("Start to execute /sysExhibition/updateByState with, id={},state={}", id, state);
        sysExhibitionService.updateByState(id,state);
        log.info("Return object for /sysExhibition/updateByState is result={}", "true");
        return InternalResponse.success();
    }

}
