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

import cn.hutool.json.JSONUtil;
import com.sikey.wa04.business.application.service.user.ChildService;
import com.sikey.wa04.business.infrastructure.configuration.ProjectContextConstant;
import com.sikey.wa04.business.infrastructure.dto.request.child.CreateChildRequest;
import com.sikey.wa04.business.infrastructure.dto.request.child.DeleteChildRequest;
import com.sikey.wa04.business.infrastructure.dto.request.child.GetPhoneNumberRequest;
import com.sikey.wa04.business.infrastructure.dto.request.child.UpdateChildRequest;
import com.sikey.wa04.business.infrastructure.dto.response.child.CreateChildResponse;
import com.sikey.wa04.business.infrastructure.dto.response.child.GetChildResponse;
import com.sikey.wa04.business.infrastructure.dto.response.child.GetPhoneNumberResponse;
import com.sikey.wa04.common.BaseController;
import com.sikey.wa04.common.dto.header.GenericManufacturerHeader;
import com.sikey.wa04.common.interceptor.Authenticated;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping(ProjectContextConstant.USER_CONTEXT_URL + "/user/child")
public class ChildController extends BaseController {

    @Resource
    private ChildService childService;

    @Authenticated
    @PostMapping("/create")
    public CreateChildResponse create(@Valid @RequestBody CreateChildRequest request) throws Exception {
        return childService.create(request);
    }

    @Authenticated
    @PostMapping("/update")
    public void update(@Valid @RequestBody UpdateChildRequest request) throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        childService.update(request, genericManufacturerHeader);
    }

    @Authenticated
    @GetMapping("/delete")
    public void delete(@Valid DeleteChildRequest request) throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        childService.delete(request.cid(), genericManufacturerHeader);
    }

    @Authenticated
    @GetMapping("/get")
    public GetChildResponse get() throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        return childService.get(genericManufacturerHeader);
    }

    /**
     * 获取手机号
     *
     * @param request 获取手机号
     * @return
     */
    @PostMapping("/getPhoneNumber")
    public GetPhoneNumberResponse getPhoneNumber(@Valid @RequestBody GetPhoneNumberRequest request) {
        log.info("[获取手机号] 参数：{}", JSONUtil.toJsonPrettyStr(request));
        return childService.getPhoneNumber(request);
    }

}
