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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.order.module.entity.PlayOrderEvaluateInfoEntity;
import com.starry.admin.modules.order.module.vo.PlayOrderEvaluateEditStateVo;
import com.starry.admin.modules.order.module.vo.PlayOrderEvaluateQueryVo;
import com.starry.admin.modules.order.module.vo.PlayOrderEvaluateReturnVo;
import com.starry.admin.modules.order.service.IPlayOrderEvaluateInfoService;
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 javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 订单评价信息Controller
 *
 * @author admin
 * @since 2024-05-07
 */
@Api(tags = "订单评价管理", description = "订单评价信息管理相关接口，包括查询、修改和删除等操作")
@RestController
@RequestMapping("/order/evaluate")
public class PlayOrderEvaluateInfoController {
    @Resource
    private IPlayOrderEvaluateInfoService playOrderEvaluateInfoService;

    /**
     * 查询订单评价信息列表
     */
    @ApiOperation(value = "分页查询评价列表", notes = "分页查询订单评价信息列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayOrderEvaluateReturnVo.class, responseContainer = "Page")})
    @PostMapping("/listByPage")
    public R list(@ApiParam(value = "查询条件", required = true) @Validated @RequestBody PlayOrderEvaluateQueryVo vo) {
        IPage<PlayOrderEvaluateReturnVo> list = playOrderEvaluateInfoService.selectByPage(vo);
        return R.ok(list);
    }

    /**
     * 修改订单评价信息
     */
    @ApiOperation(value = "修改评价状态", notes = "修改订单评价的显示状态")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "修改失败")})
    // @PreAuthorize("@customSs.hasPermission('order:evaluate:update')")
    @Log(title = "修改订单评价状态", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateStatus")
    public R update(
            @ApiParam(value = "评价状态信息", required = true) @Validated @RequestBody PlayOrderEvaluateEditStateVo vo) {
        PlayOrderEvaluateInfoEntity entity = ConvertUtil.entityToVo(vo, PlayOrderEvaluateInfoEntity.class);
        boolean success = playOrderEvaluateInfoService.update(entity);
        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)})
    // @PreAuthorize("@customSs.hasPermission('order:evaluate:delete')")
    @Log(title = "订单评价信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playOrderEvaluateInfoService.deletePlayOrderEvaluateInfoByIds(ids));
    }
}
