package com.yiqi.admin.controller.app;

import java.util.List;
import javax.validation.Valid;

import com.yiqi.app.domain.dto.AppCouponTypeApplyClothDTO;
import com.yiqi.app.domain.vo.AppCouponTypeApplyClothVO;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.core.domain.dto.ClothItemDTO;
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.app.domain.AppCouponTypeApplyCloth;
import com.yiqi.app.service.IAppCouponTypeApplyClothService;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 优惠券可使用衣物Controller
 *
 * @author xiaohei
 * @date 2023-09-20
 */
@Api(tags = "管理后台 - 优惠券可使用衣物")
@RestController
@RequestMapping(UrlConstants.managerApi + "/app/couponTypeApplyCloth")
public class AppCouponTypeApplyClothController extends BaseController {
    @Autowired
    private IAppCouponTypeApplyClothService appCouponTypeApplyClothService;

    /**
     * 查询优惠券可使用衣物列表
     */
    @PreAuthorize("@ss.hasPermi('coupon:type:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询优惠券可使用衣物列表")
    public TableDataInfo list(ClothItemDTO clothItemDTO) {
        startPage();
        List<AppCouponTypeApplyClothVO> list = appCouponTypeApplyClothService.selectAppCouponTypeApplyClothList(clothItemDTO);
        return getDataTable(list);
    }

    /**
     * 获取优惠券可使用衣物详细信息
     */
    @PreAuthorize("@ss.hasPermi('coupon:type:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取优惠券可使用衣物详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appCouponTypeApplyClothService.selectAppCouponTypeApplyClothById(id));
    }

    /**
     * 新增优惠券可使用衣物
     */
    @PreAuthorize("@ss.hasPermi('coupon:type:add')")
    @Log(title = "优惠券可使用衣物", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增优惠券可使用衣物")
    public AjaxResult add(@RequestBody @Valid AppCouponTypeApplyClothDTO appCouponTypeApplyClothDTO) {
        return toAjax(appCouponTypeApplyClothService.insertAppCouponTypeApplyCloth(appCouponTypeApplyClothDTO));
    }

    /**
     * 修改优惠券可使用衣物
     */
    @PreAuthorize("@ss.hasPermi('coupon:type:edit')")
    @Log(title = "优惠券可使用衣物", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改优惠券可使用衣物")
    public AjaxResult edit(@RequestBody @Valid AppCouponTypeApplyCloth appCouponTypeApplyCloth) {
        appCouponTypeApplyCloth.setUpdateById(getUserId());
        appCouponTypeApplyCloth.setUpdateBy(getUsername());
        return toAjax(appCouponTypeApplyClothService.updateAppCouponTypeApplyCloth(appCouponTypeApplyCloth));
    }

    /**
     * 删除优惠券可使用衣物
     */
    @PreAuthorize("@ss.hasPermi('coupon:type:remove')")
    @Log(title = "优惠券可使用衣物", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除优惠券可使用衣物")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appCouponTypeApplyClothService.deleteAppCouponTypeApplyClothByIds(ids));
    }

}
