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.StatusType;
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.core.domain.ClothWashMode;
import com.yiqi.core.service.IClothWashModeService;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 洗衣方式Controller
 *
 * @author ruoyi
 * @date 2023-08-09
 */
@Api(tags = "洗衣方式")
@RestController
@RequestMapping("/mapi/core/washMode")
public class ClothWashModeController extends BaseController {
    @Autowired
    private IClothWashModeService clothWashModeService;

    /**
    * 查询洗衣方式列表
    */
//    @PreAuthorize("@ss.hasPermi('cloth:washMode:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClothWashMode clothWashMode) {
        startPage();
        List<ClothWashMode> list = clothWashModeService.selectClothWashModeList(clothWashMode);
        return getDataTable(list);
    }

    /**
     * 获取洗衣方式详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloth:washMode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clothWashModeService.selectClothWashModeById(id));
    }

    /**
     * 新增洗衣方式
     */
    @PreAuthorize("@ss.hasPermi('cloth:washMode:add')")
    @Log(title = "洗衣方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClothWashMode clothWashMode) {
        return toAjax(clothWashModeService.insertClothWashMode(clothWashMode));
    }

    /**
     * 修改洗衣方式
     */
    @PreAuthorize("@ss.hasPermi('cloth:washMode:edit')")
    @Log(title = "洗衣方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClothWashMode clothWashMode) {
        return toAjax(clothWashModeService.updateClothWashMode(clothWashMode));
    }

    /**
     * 删除洗衣方式
     */
    @PreAuthorize("@ss.hasPermi('cloth:washMode:remove')")
    @Log(title = "洗衣方式", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(clothWashModeService.deleteClothWashModeByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('cloth:washMode:edit')")
    @Log(title = "洗衣方式", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody ClothWashMode clothWashMode) {
        return toAjax(clothWashModeService.updateWashModeStatus(clothWashMode));
    }

    @ApiOperation("洗衣方式维度 - 查询洗衣方式")
    @GetMapping
    public R<List<ClothWashMode>> getClothWashModeList() {
        List<ClothWashMode> list = clothWashModeService.list(new QueryWrapper<ClothWashMode>().lambda()
                .eq(ClothWashMode::getDelFlag, StatusType.OK.getCode())
                .eq(ClothWashMode::getStatus, StatusType.OK.getCode()));
        return R.ok(list);
    }
}
