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

import com.sikey.wa04.business.application.service.user.FriendService;
import com.sikey.wa04.business.infrastructure.configuration.ProjectContextConstant;
import com.sikey.wa04.business.infrastructure.dto.request.contact.AddFriendRequest;
import com.sikey.wa04.business.infrastructure.dto.request.contact.GenerateFriendCodeRequest;
import com.sikey.wa04.business.infrastructure.dto.response.contact.AddFriendResponse;
import com.sikey.wa04.business.infrastructure.dto.response.contact.GenerateFriendCodeResponse;
import com.sikey.wa04.common.BaseController;
import com.sikey.wa04.common.dto.header.GenericManufacturerHeader;
import com.sikey.wa04.common.interceptor.Authenticated;
import com.sikey.wa04.common.interceptor.CurrentRequestUser;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(ProjectContextConstant.USER_CONTEXT_URL + "/user/child/contacts/wristwatch")
public class FriendWristwatchController extends BaseController {
    private final FriendService friendService;

    public FriendWristwatchController(FriendService friendServiceImpl) {
        this.friendService = friendServiceImpl;
    }

    /**
     * 生成好友码
     *
     * @return ResponseEntity<Object>
     */
    @Authenticated
    @PostMapping("/friend/generate-code")
    public GenerateFriendCodeResponse generateFriendCode(@Valid @RequestBody GenerateFriendCodeRequest request) throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        return friendService.generateCode(request,genericManufacturerHeader);
    }

    /**
     * 添加好友
     *
     * @param request AddFriendRequest
     * @return ResponseEntity<Object>
     */
    @Authenticated
    @PostMapping("/friend/add")
    public AddFriendResponse addFriend(@Valid @RequestBody AddFriendRequest request) {
        request.setId(CurrentRequestUser.get().getId());
        request.setHeaders(genericManufacturerHeader());
        return friendService.addFriend(request);
    }

}
