package com.yuchen.saas.park.service.controller.property;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.dto.property.PropertyFeeItemAddDto;
import com.yuchen.saas.park.api.dto.property.PropertyFeeItemQueryDto;
import com.yuchen.saas.park.api.dto.property.PropertyFeeItemUpdateStatusDto;
import com.yuchen.saas.park.api.enums.property.FeeItemTypeEnum;
import com.yuchen.saas.park.api.vo.property.PropertyFeeItemPageVo;
import com.yuchen.saas.park.api.vo.property.PropertyFeeItemSubjectVo;
import com.yuchen.saas.park.service.service.property.IPropertyFeeItemService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 费用项目 前端控制器
 * </p>
 *
 * @author cxj
 * @since 2023-12-12
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/propertyFeeItem")
public class PropertyFeeItemController {

    private final IPropertyFeeItemService baseService;

    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增/修改", notes = "新增/修改")
    public R saveOrUpdate(@RequestBody PropertyFeeItemAddDto dto) {
        return R.status(baseService.saveOrUpdate(dto));
    }

    @GetMapping("getPage")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "收费项目分页查询", notes = "收费项目分页查询")
    public R<NestPage<PropertyFeeItemPageVo>> getPage(PropertyFeeItemQueryDto dto) {
        NestPage<PropertyFeeItemPageVo> page = baseService.getPage(dto);
        return R.data(page);
    }

    @GetMapping("listFeeSubject")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "收费项目类型下拉", notes = "收费项目类型下拉")
    public R<List<PropertyFeeItemSubjectVo>> listFeeSubject() {
        List<PropertyFeeItemSubjectVo> list = FeeItemTypeEnum.list();
        return R.data(list);
    }

    @PostMapping("/delete")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "删除")
    public R delete(@Valid @RequestBody CommonIdParam param) {
        return R.status(baseService.del(param.getId()));
    }

    @PostMapping("/updateStatus")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "启用或停用", notes = "启用或停用")
    public R updateStatus(@Valid @RequestBody PropertyFeeItemUpdateStatusDto param) {
        return R.status(baseService.updateStatus(param));
    }

    @GetMapping("getDetailById")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "收费项目详情", notes = "收费项目详情")
    public R<PropertyFeeItemPageVo> getDetailById(@ApiParam(value = "id") @RequestParam(value = "id") Long id) {
        PropertyFeeItemPageVo vo = baseService.getDetailById(id);
        return R.data(vo);
    }
}
