package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.LifeUserCreditScoreInfo;
import shop.alien.store.service.LifeUserCreditScoreInfoService;

@Api(tags = {"用户信用分信息"})
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/lifeUserCreditScoreInfo")
@RequiredArgsConstructor
public class LifeUserCreditScoreInfoController {

    private final LifeUserCreditScoreInfoService lifeUserCreditScoreInfoService;

    @ApiOperation("新增用户信用分信息")
    @ApiOperationSupport(order = 1)
    @PostMapping("/add")
    public R<String> add(@RequestBody LifeUserCreditScoreInfo lifeUserCreditScoreInfo) {
        return lifeUserCreditScoreInfoService.add(lifeUserCreditScoreInfo);
    }

    @ApiOperation("根据ID删除用户信用分信息")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/deleteById")
    public R<String> deleteById(@RequestParam Integer id) {
        return lifeUserCreditScoreInfoService.deleteById(id);
    }

    @ApiOperation("更新用户信用分信息")
    @ApiOperationSupport(order = 3)
    @PostMapping("/update")
    public R<String> update(@RequestBody LifeUserCreditScoreInfo lifeUserCreditScoreInfo) {
        return lifeUserCreditScoreInfoService.update(lifeUserCreditScoreInfo);
    }

    @ApiOperation("根据ID查询用户信用分信息")
    @ApiOperationSupport(order = 4)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getById")
    public R<LifeUserCreditScoreInfo> getById(@RequestParam Integer id) {
        return lifeUserCreditScoreInfoService.getInfoById(id);
    }

    @ApiOperation("根据用户ID查询用户信用分信息")
    @ApiOperationSupport(order = 5)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getByUserId")
    public R<LifeUserCreditScoreInfo> getByUserId(@RequestParam Integer userId) {
        return lifeUserCreditScoreInfoService.getByUserId(userId);
    }

    @ApiOperation("分页查询用户信用分信息列表")
    @ApiOperationSupport(order = 6)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Integer", paramType = "query")
    })
    @GetMapping("/list")
    public R<IPage<LifeUserCreditScoreInfo>> list(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestParam(required = false) Integer userId) {
        return lifeUserCreditScoreInfoService.list(pageNum, pageSize, userId);
    }
}
