package com.sikey.wa04.api.user.client.rest;

import com.sikey.wa04.business.application.service.user.ChildService;
import com.sikey.wa04.business.infrastructure.configuration.ProjectContextConstant;
import com.sikey.wa04.business.infrastructure.dto.response.blockunknowncall.GetBlockUnknownCallResponse;
import com.sikey.wa04.common.BaseController;
import com.sikey.wa04.common.dto.header.GenericManufacturerHeader;
import com.sikey.wa04.common.interceptor.Authenticated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(ProjectContextConstant.USER_CONTEXT_URL + "/user/child/block-unknown-call")
public class BlockUnknownCallController extends BaseController {
    private final ChildService childService;

    @Autowired
    public BlockUnknownCallController(ChildService childService) {
        this.childService = childService;
    }

    /**
     * 获取是否拦截未知号码
     *
     * @param cid 孩子id
     * @return 是否拦截未知号码
     */
    @Authenticated
    @GetMapping("/get")
    public GetBlockUnknownCallResponse get(@RequestParam("cid") String cid) {
        return childService.getBlockUnknownCall(cid);
    }

    /**
     * 切换是否拦截未知号码
     *
     * @param cid      孩子id
     * @param isEnable 是否拦截
     */
    @Authenticated
    @GetMapping("/toggle")
    public void toggle(@RequestParam("cid") String cid, @RequestParam("isEnable") boolean isEnable) {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        childService.updateBlockUnknownCall(cid, isEnable,genericManufacturerHeader);
    }
}
