package com.yiqi.admin.controller.core;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yiqi.common.core.domain.R;
import com.yiqi.common.enums.DeleteStatus;
import com.yiqi.common.enums.StatusType;
import com.yiqi.core.domain.ClothColor;
import com.yiqi.core.service.IClothColorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.common.core.page.TableDataInfo;

/**
 * 衣服颜色Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@Api(tags = "衣服颜色管理")
@RestController
@RequestMapping("/mapi/core/color")
public class ClothColorController extends BaseController {
    @Autowired
    private IClothColorService clothColorService;

    @ApiOperation("获取所有衣服颜色")
    @GetMapping("/all")
    public R list() {
        return R.ok(clothColorService.list(new QueryWrapper<ClothColor>().lambda()
                .eq(ClothColor::getDelFlag, DeleteStatus.OK.getCode())
                .eq(ClothColor::getStatus, StatusType.OK.getCode())
                .orderByAsc(ClothColor::getSort)));
    }

    /**
    * 查询衣服颜色列表
    */
    @PreAuthorize("@ss.hasPermi('cloth:color:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClothColor clothColor) {
        startPage();
        List<ClothColor> list = clothColorService.selectClothColorList(clothColor);
        return getDataTable(list);
    }

    /**
     * 获取衣服颜色详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloth:color:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clothColorService.selectClothColorById(id));
    }

    /**
     * 新增衣服颜色
     */
    @PreAuthorize("@ss.hasPermi('cloth:color:add')")
    @Log(title = "衣服颜色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClothColor clothColor) {
        return toAjax(clothColorService.insertClothColor(clothColor));
    }

    /**
     * 修改衣服颜色
     */
    @PreAuthorize("@ss.hasPermi('cloth:color:edit')")
    @Log(title = "衣服颜色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClothColor clothColor) {
        return toAjax(clothColorService.updateClothColor(clothColor));
    }

    /**
     * 删除衣服颜色
     */
    @PreAuthorize("@ss.hasPermi('cloth:color:remove')")
    @Log(title = "衣服颜色", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(clothColorService.deleteClothColorByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('cloth:color:edit')")
    @Log(title = "衣服颜色", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody ClothColor clothColor) {
        clothColor.setUpdateBy(getUsername());
        return toAjax(clothColorService.updateColorStatus(clothColor));
    }
}
