package com.lottery.type.controller;

import com.lottery.type.entity.TdLottery;
import com.lottery.type.service.TdLotteryService;
import lombok.extern.slf4j.Slf4j;
import com.lottery.type.param.TdLotteryPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.common.param.IdParam;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 彩种 控制器
 *
 * @author fxf
 * @since 2020-09-07
 */
@Slf4j
@RestController
@RequestMapping("/tdLottery")
@Module("type")
@Api(value = "彩种API", tags = {"彩种"})
public class TdLotteryController extends BaseController {

    @Autowired
    private TdLotteryService tdLotteryService;

    /**
     * 添加彩种
     */
    @PostMapping("/add")
    @OperationLog(name = "添加彩种", type = OperationLogType.ADD)
    @ApiOperation(value = "添加彩种", response = ApiResult.class)
    public ApiResult<Boolean> addTdLottery(@Validated(Add.class) @RequestBody TdLottery tdLottery) throws Exception {
        boolean flag = tdLotteryService.saveTdLottery(tdLottery);
        return ApiResult.result(flag);
    }

    /**
     * 修改彩种
     */
    @PostMapping("/update")
    @OperationLog(name = "修改彩种", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改彩种", response = ApiResult.class)
    public ApiResult<Boolean> updateTdLottery(@Validated(Update.class) @RequestBody TdLottery tdLottery) throws Exception {
        boolean flag = tdLotteryService.updateTdLottery(tdLottery);
        return ApiResult.result(flag);
    }

    /**
     * 删除彩种
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除彩种", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除彩种", response = ApiResult.class)
    public ApiResult<Boolean> deleteTdLottery(@PathVariable("id") Long id) throws Exception {
        boolean flag = tdLotteryService.deleteTdLottery(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取彩种详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "彩种详情", type = OperationLogType.INFO)
    @ApiOperation(value = "彩种详情", response = TdLottery.class)
    public ApiResult<TdLottery> getTdLottery(@PathVariable("id") Long id) throws Exception {
        TdLottery tdLottery = tdLotteryService.getById(id);
        return ApiResult.ok(tdLottery);
    }

    /**
     * 彩种分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "彩种分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "彩种分页列表", response = TdLottery.class)
    public ApiResult<Paging<TdLottery>> getTdLotteryPageList(@Validated @RequestBody TdLotteryPageParam tdLotteryPageParam) throws Exception {
        Paging<TdLottery> paging = tdLotteryService.getTdLotteryPageList(tdLotteryPageParam);
        return ApiResult.ok(paging);
    }

}

