package com.chuanxia.mcp.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chuanxia.mcp.aop.Login;
import com.chuanxia.mcp.bean.dto.DomainBindDto;
import com.chuanxia.mcp.bean.dto.DomainCityQueryDto;
import com.chuanxia.mcp.bean.model.CdnCity;
import com.chuanxia.mcp.bean.vo.CdnDomainCityVo;
import com.chuanxia.mcp.bean.vo.Result;
import com.chuanxia.mcp.service.CdnDoaminService;
import com.chuanxia.mcp.service.CdnService;
import com.chuanxia.mcp.service.CdnDomainCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api("区域绑定")
@RequestMapping("cdnDomainCity")
@RequiredArgsConstructor
public class CdnDomainCityController {
    private final CdnService cdnService;
    private final CdnDoaminService doaminService;
    private final CdnDomainCityService domainCityService;

    @GetMapping("cascade")
    @ApiOperation("级联查询城市信息")
    @Login
    public Result<List<CdnCity>> cascade(@RequestParam(value = "parentId", required = false, defaultValue = "1") Integer parentId) {
        return cdnService.cascade(parentId);
    }

    @PostMapping("listPage")
    @ApiOperation("分页获取区域域名列表")
    @Login
    public Result<IPage<CdnDomainCityVo>> listPage(@RequestBody DomainCityQueryDto queryDto) {
        return domainCityService.listPage(queryDto);
    }

    @GetMapping("deleteById")
    @ApiOperation("删除绑定")
    @Login
    public Result<String> deleteById(@RequestParam("id") Integer id) {
        domainCityService.removeById(id);
        return Result.success("操作成功");
    }

    @PostMapping("bindCdn")
    @ApiOperation("域名绑定城市")
    @Login
    public Result<String> bindCdn(@RequestBody DomainBindDto bindDto) {
        return doaminService.bindCdn(bindDto);
    }


}
