package com.chuanxia.mcp.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chuanxia.mcp.aop.Login;
import com.chuanxia.mcp.bean.dto.DomainTimeRuleBindDto;
import com.chuanxia.mcp.bean.dto.DomainTimeRuleQueryDto;
import com.chuanxia.mcp.bean.model.CdnTimeRule;
import com.chuanxia.mcp.bean.vo.CdnDomainTimeRuleVo;
import com.chuanxia.mcp.bean.vo.Result;
import com.chuanxia.mcp.service.CdnTimeRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("cdnTimeRule")
@Api("时间规则配置")
public class CdnTimeRuleController {
    private final CdnTimeRuleService ruleService;

    @PostMapping("bindTimeRule")
    @ApiOperation("绑定时间规则")
    @Login
    public Result<String> bindTimeRule(@RequestBody DomainTimeRuleBindDto timeRule) {
        return ruleService.bindTimeRule(timeRule);
    }

    @PostMapping("listPage")
    @ApiOperation("域名-时间规则分页列表")
    @Login
    public Result<IPage<CdnDomainTimeRuleVo>> listPage(@RequestBody DomainTimeRuleQueryDto queryDto) {
        return ruleService.listPage(queryDto);
    }

    @GetMapping("deleteById")
    @ApiOperation("删除时间规则")
    @Login
    public Result deleteById(@RequestParam("id") Integer id) {
        return ruleService.deleteById(id);
    }
}
