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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.commodity.module.entity.PlayServiceInfoEntity;
import com.starry.admin.modules.commodity.service.IPlayServiceInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 服务项目列表Controller
 *
 * @author admin
 * @since 2024-03-28
 */
@RestController
@RequestMapping("/commodity/info")
public class PlayServiceInfoController {
    @Resource
    private IPlayServiceInfoService playServiceInfoService;



    /**
     * 查询服务项目列表列表
     */
    @GetMapping("/list")
    public R list(PlayServiceInfoEntity playServiceInfo) {
        IPage<PlayServiceInfoEntity> list = playServiceInfoService.selectPlayServiceInfoByPage(playServiceInfo);
        return R.ok(list);
    }

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

    /**
     * 新增服务项目列表
     */
    @Log(title = "服务项目列表", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayServiceInfoEntity playServiceInfo) {
        boolean success = playServiceInfoService.create(playServiceInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

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

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