package com.ruoyi.web.controller.tool;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.R;
import com.ruoyi.system.domain.SiteConfig;
import com.ruoyi.system.domain.SiteInfo;
import com.ruoyi.system.dto.SiteConfigDTO;
import com.ruoyi.system.dto.SiteInfoDTO;
import com.ruoyi.system.paramet.SiteInfoQuery;
import com.ruoyi.system.service.SiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * @author ifei
 */
@RestController
@RequestMapping("/site")
@Api(tags = "站点管理")
@Anonymous
public class SiteController {

    @Resource
    private SiteService siteService;

    @PostMapping(value = "/insert")
    @ApiOperation("新增站点")
    public R<Boolean> insert(@Valid @RequestBody SiteInfoDTO siteInfoDTO)  {
        return R.ok(siteService.insert(siteInfoDTO));
    }

    @PostMapping(value = "/query")
    @ApiOperation("查询站点")
    public R<Page<SiteInfo>> query(@RequestBody SiteInfoQuery siteInfoQuery) {
        return R.ok(siteService.query(siteInfoQuery));
    }

    @GetMapping(value = "/{id}")
    @ApiOperation("站点详情")
    public R<SiteInfo> queryById(@PathVariable("id") Long id) {
        return R.ok(siteService.queryById(id));
    }

    @PostMapping(value = "/update")
    @ApiOperation("修改站点")
    public R<Boolean> update(@Valid @RequestBody SiteInfoDTO siteInfoDTO) {
        return R.ok(siteService.update(siteInfoDTO));
    }


    @PostMapping(value = "/insertConfig")
    @ApiOperation("新增站点配置")
    public R<Boolean> insertConfig(@Valid @RequestBody SiteConfigDTO siteConfigDTO)  {
        return R.ok(siteService.insertConfig(siteConfigDTO));
    }

    @GetMapping(value = "/queryConfig/{siteId}")
    @ApiOperation("查询站点配置")
    public R<SiteConfig> queryConfig(@PathVariable("siteId") Long siteId)  {
        return R.ok(siteService.queryConfig(siteId));
    }

    @PostMapping(value = "/updateConfig")
    @ApiOperation("修改站点配置")
    public R<Boolean> updateConfig(@Valid @RequestBody SiteConfigDTO siteConfigDTO)  {
        return R.ok(siteService.updateConfig(siteConfigDTO));
    }

    @DeleteMapping(value = "/delete/{siteId}")
    @ApiOperation("删除站点")
    public R<Boolean> delete(@PathVariable("siteId") Long siteId) {
        return R.ok(siteService.delete(siteId));
    }


}
