package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
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.LifeUser;
import shop.alien.entity.store.vo.LifeUserVo;
import shop.alien.store.service.PlatformLifeUserService;

@Api(tags = {"平台-用户管理"})
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/platformLifeUser")
@RequiredArgsConstructor
public class PlatformLifeUserController {

    private final PlatformLifeUserService platformLifeUserService;

    @ApiOperation("用户列表")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页页数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "realName", value = "姓名", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userPhone", value = "手机号码", dataType = "String", paramType = "query")})
    @GetMapping("/getUserList")
    public R<IPage<LifeUserVo>> getUserList(@RequestParam("page") Integer page, @RequestParam("size") Integer size, String realName, String userPhone) {
        log.info("PlatformLifeUserController.getUserList?page={},size={},name={},phone={}", page, size, realName, userPhone);
        IPage<LifeUserVo> userList = platformLifeUserService.getUserList(page, size, realName, userPhone);
        return R.data(userList);
    }

    @ApiOperation("用户详情")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "用户id", dataType = "Integer", paramType = "query", required = true)})
    @GetMapping("/getUserById")
    public R<LifeUser> getUserById(Integer id) {
        log.info("PlatformLifeUserController.getUserById?id={}", id);
        return R.data(platformLifeUserService.getUserById(id));
    }

}
