package com.yiqi.admin.controller.core;

import java.util.List;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.core.domain.ClothCustomItem;
import com.yiqi.core.service.IClothCustomItemService;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 自定义衣物Controller
 *
 * @author ruoyi
 * @date 2023-08-07
 */
@Api(tags = "自定义衣物管理")
@RestController
@RequestMapping("/mapi/core/customItem")
public class ClothCustomItemController extends BaseController {
    @Autowired
    private IClothCustomItemService clothItemService;

    /**
    * 查询自定义衣物列表
    */
    @PreAuthorize("@ss.hasPermi('cloth:customItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClothCustomItem clothCustomItem) {
        startPage();
        List<ClothCustomItem> list = clothItemService.selectClothItemList(clothCustomItem);
        return getDataTable(list);
    }

    /**
     * 获取自定义衣物详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloth:customItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clothItemService.selectClothItemById(id));
    }

    /**
     * 新增自定义衣物
     */
    @PreAuthorize("@ss.hasPermi('cloth:customItem:add')")
    @Log(title = "自定义衣物", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClothCustomItem clothCustomItem) {
        return toAjax(clothItemService.insertClothItem(clothCustomItem));
    }

    /**
     * 修改自定义衣物
     */
    @PreAuthorize("@ss.hasPermi('cloth:customItem:edit')")
    @Log(title = "自定义衣物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClothCustomItem clothCustomItem) {
        return toAjax(clothItemService.updateClothItem(clothCustomItem));
    }

    /**
     * 删除自定义衣物
     */
    @PreAuthorize("@ss.hasPermi('cloth:customItem:remove')")
    @Log(title = "自定义衣物", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(clothItemService.deleteClothItemByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('cloth:customItem:edit')")
    @Log(title = "自定义衣物", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody ClothCustomItem clothCustomItem) {
        return toAjax(clothItemService.updateItemStatus(clothCustomItem));
    }
}
