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.*;
import com.yuchen.saas.park.api.entity.property.PropertyPayReduction;
import com.yuchen.saas.park.api.vo.property.*;
import com.yuchen.saas.park.service.service.property.IPropertyPayReductionService;
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 javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 减免活动-缴费减免 前端控制器
 * </p>
 *
 * @author cxj
 * @since 2023-12-22
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/propertyPayReduction")
public class PropertyPayReductionController {

    private final IPropertyPayReductionService baseService;

    @GetMapping("/getPage")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "减免活动-缴费减免分页", notes = "减免活动-缴费减免分页")
    public R<NestPage<PropertyPayReductionPageVo>> getPage(@Valid PropertyPayReductionQueryDto dto) {
        NestPage<PropertyPayReductionPageVo> page = baseService.getPage(dto);
        return R.data(page);
    }

    @PostMapping("/addOrUpdate")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "新增/编辑", notes = "新增/编辑")
    public R addOrUpdate(@Valid @RequestBody PropertyPayReductionAddDto dto) {
        return R.status(baseService.addOrUpdate(dto));
    }

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

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

    @PostMapping("/audit")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "审核", notes = "审核")
    public R audit(@Valid @RequestBody PropertyPayReductionAuditDto param) {
        return R.status(baseService.audit(param));
    }

    @GetMapping("getDetailById")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "减免活动-详情(编辑回显)", notes = "减免活动-详情(编辑回显)")
    public R<PropertyPayReductionDetailVo> getDetailById(@ApiParam(value = "id", required = true)@NotNull @RequestParam Long id) {
        PropertyPayReductionDetailVo vo = baseService.getDetailById(id);
        return R.data(vo);
    }

    @GetMapping("getAuditById")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "减免活动-详情(审核回显)", notes = "减免活动-详情(审核回显)")
    public R<PropertyPayReductionAuditVo> getAuditById(@ApiParam(value = "id", required = true)@NotNull @RequestParam Long id) {
        PropertyPayReductionAuditVo vo = baseService.getAuditById(id);
        return R.data(vo);
    }

    @PostMapping("/extendTime")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "延长时间", notes = "延长时间")
    public R extendTime(@Valid @RequestBody PropertyPayReductionExtendTimeDto param) {
        return R.status(baseService.extendTime(param));
    }

    @GetMapping("listByParkId")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "调整活动顺序列表", notes = "调整活动顺序列表")
    public R<List<PropertyPayReduction>> listByParkId(@ApiParam(value = "parkId", required = true)@NotNull @RequestParam Long parkId) {
        List<PropertyPayReduction> list = baseService.listByParkId(parkId);
        return R.data(list);
    }

    @PostMapping("/sort")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "排序(从小到大传)", notes = "排序(从小到大传)")
    public R sort(@Valid @RequestBody PropertyPayReductionSortDto param) {
        return R.status(baseService.sort(param));
    }
}
