package com.njzscloud.dispose.sys.endpoint.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.dispose.sys.endpoint.pojo.param.AddEndpointParam;
import com.njzscloud.dispose.sys.endpoint.pojo.param.EndpointSearchParam;
import com.njzscloud.dispose.sys.endpoint.pojo.param.ModifyEndpointParam;
import com.njzscloud.dispose.sys.endpoint.pojo.result.EndpointDetailResult;
import com.njzscloud.dispose.sys.endpoint.service.EndpointService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 端点信息表
 */
@Slf4j
@RestController
@RequestMapping("/endpoint")
@RequiredArgsConstructor
public class EndpointController {

    private final EndpointService endpointService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody AddEndpointParam addEndpointParam) {
        endpointService.add(addEndpointParam);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody ModifyEndpointParam modifyEndpointParam) {
        endpointService.modify(modifyEndpointParam);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        endpointService.del(ids);
        return R.success();
    }

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<EndpointDetailResult> detail(@RequestParam("id") Long id) {
        return R.success(endpointService.detail(id));
    }

    /**
     * 查询
     */
    @GetMapping("/list_all")
    public R<List<EndpointDetailResult>> listAll(EndpointSearchParam endpointSearchParam) {
        return R.success(endpointService.listAll(endpointSearchParam));
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<EndpointDetailResult>> paging(PageParam pageParam, EndpointSearchParam endpointSearchParam) {
        return R.success(endpointService.paging(pageParam, endpointSearchParam));
    }
    /**
     * 重新加载资源
     */
    @GetMapping("/reload")
    public R<?> reload() {
        endpointService.saveAll();
        return R.success();
    }

}
