package com.starry.admin.modules.clerk.controller;

import com.starry.admin.common.oss.service.IOssFileService;
import com.starry.admin.modules.clerk.module.entity.PlayAvatarFrameInfoEntity;
import com.starry.admin.modules.clerk.module.vo.PlayAvatarFrameInfoAddVo;
import com.starry.admin.modules.clerk.module.vo.PlayAvatarFrameInfoQueryVo;
import com.starry.admin.modules.clerk.module.vo.PlayAvatarFrameSendVo;
import com.starry.admin.modules.clerk.service.IPlayAvatarFrameInfoService;
import com.starry.admin.utils.SecurityUtils;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import com.starry.common.utils.ConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.io.IOException;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 店员头像框Controller
 *
 * @author admin
 * @since 2024-06-06
 */
@Api(tags = "店员头像框管理", description = "店员头像框信息管理相关接口，包括查询、新增、修改、删除和赠送等操作")
@RestController
@RequestMapping("/clerk/avatarFrame")
public class PlayAvatarFrameInfoController {
    @Resource
    private IPlayAvatarFrameInfoService playAvatarFrameInfoService;

    @Resource
    private IOssFileService ossFileService;

    @ApiOperation(value = "分页查询头像框", notes = "分页查询店员头像框信息列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayAvatarFrameInfoEntity.class, responseContainer = "Page")})
    @PostMapping("/listByPage")
    public R listByPage(
            @ApiParam(value = "查询条件", required = true) @Validated @RequestBody PlayAvatarFrameInfoQueryVo vo) {
        return R.ok(playAvatarFrameInfoService.selectByPage(vo));
    }

    /**
     * 查询店员头像框列表
     */
    @ApiOperation(value = "查询所有头像框", notes = "获取所有店员头像框信息列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayAvatarFrameInfoEntity.class, responseContainer = "List")})
    @GetMapping("/listAll")
    public R listAll() {
        return R.ok(playAvatarFrameInfoService.selectAll());
    }

    @ApiOperation(value = "上传头像框图片", notes = "上传店员头像框图片文件")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = String.class, responseContainer = "R")})
    @PostMapping("/uploadFile")
    public R uploadFile(@ApiParam(value = "图片文件", required = true) @RequestParam("file") MultipartFile file)
            throws IOException {
        String fileAddress = ossFileService.upload(file.getInputStream(), SecurityUtils.getTenantId(),
                file.getOriginalFilename());
        return R.ok(fileAddress);
    }

    /**
     * 新增店员头像框
     */
    @ApiOperation(value = "新增头像框", notes = "创建新的店员头像框信息")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "添加失败")})
    @Log(title = "店员头像框", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@ApiParam(value = "头像框信息", required = true) @Validated @RequestBody PlayAvatarFrameInfoAddVo vo) {
        boolean success = playAvatarFrameInfoService
                .create(ConvertUtil.entityToVo(vo, PlayAvatarFrameInfoEntity.class));
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改店员头像框
     */
    @ApiOperation(value = "修改头像框", notes = "根据ID修改店员头像框信息")
    @ApiImplicitParam(name = "id", value = "头像框ID", required = true, paramType = "path", dataType = "String", example = "1")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "修改失败")})
    @Log(title = "店员头像框", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id,
            @ApiParam(value = "头像框信息", required = true) @RequestBody PlayAvatarFrameInfoEntity playAvatarFrameInfo) {
        playAvatarFrameInfo.setId(id);
        boolean success = playAvatarFrameInfoService.update(playAvatarFrameInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除店员头像框
     */
    @ApiOperation(value = "删除头像框", notes = "根据ID批量删除店员头像框信息")
    @ApiImplicitParam(name = "ids", value = "头像框ID数组", required = true, paramType = "path", dataType = "String[]", example = "1,2,3")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = Integer.class)})
    @Log(title = "店员头像框", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playAvatarFrameInfoService.deletePlayAvatarFrameInfoByIds(ids));
    }

    /**
     * 新增店员头像框
     */
    @ApiOperation(value = "赠送头像框", notes = "赠送头像框给指定店员")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "添加失败")})
    @Log(title = "赠送店员头像框", businessType = BusinessType.INSERT)
    @PostMapping("/sendAvatarFrame")
    public R sendAvatarFrame(
            @ApiParam(value = "赠送信息", required = true) @Validated @RequestBody PlayAvatarFrameSendVo vo) {
        return R.error("添加失败");
    }

}
