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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.play.module.entity.PlayCommodityInfoEntity;
import com.starry.admin.modules.play.module.vo.PlayCommodityInfoAddVo;
import com.starry.admin.modules.play.service.IPlayCommodityInfoService;
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 org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 服务项目Controller
 *
 * @author admin
 * @since 2024-03-31
 */
@RestController
@RequestMapping("/play/commodity")
public class PlayCommodityInfoController {
    @Resource
    private IPlayCommodityInfoService playCommodityInfoService;

    /**
     * 查询服务项目列表
     */
    @GetMapping("/list")
    public R list(PlayCommodityInfoEntity playCommodityInfo) {
        IPage<PlayCommodityInfoEntity> list = playCommodityInfoService.selectPlayCommodityInfoByPage(playCommodityInfo);
        return R.ok(list);
    }

    /**
     * 获取服务项目详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playCommodityInfoService.selectPlayCommodityInfoById(id));
    }

    /**
     * 新增服务项目
     */
    @Log(title = "服务项目", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayCommodityInfoAddVo vo) {
        PlayCommodityInfoEntity entity = ConvertUtil.entityToVo(vo, PlayCommodityInfoEntity.class);
        boolean success = playCommodityInfoService.create(entity);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改服务项目
     */
    @Log(title = "服务项目", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayCommodityInfoEntity playCommodityInfo) {
        playCommodityInfo.setId(id);
        boolean success = playCommodityInfoService.update(playCommodityInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除服务项目
     */
    @Log(title = "服务项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playCommodityInfoService.deletePlayCommodityInfoByIds(ids));
    }
}
