package com.xingxi.store.controller;

import com.xingxi.store.common.BaseApiController;
import com.xingxi.store.model.*;
import com.xingxi.store.service.UserProfileServiceI;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RequiredArgsConstructor
@RestController
@Validated
@RequestMapping("/api/store")
public class UserProfileApiController extends BaseApiController {
    private final UserProfileServiceI userProfileServiceI;

    @GetMapping("/user-profile")
    public UserProfileResponse userProfile(UserProfileRequest request) {
        return userProfileServiceI.getUserProfile(getUserContext(), request);
    }

    @PostMapping("/user-profile")
    public UserProfileUpdateResponse userProfileUpdate(@Valid @RequestBody UserProfileUpdateRequest request) {
        return userProfileServiceI.updateUserProfile(getUserContext(), request);
    }

    @PostMapping("/user-profile/upload-avatar")
    public UserProfileUpdateResponse saveAvatar(@RequestBody UserProfileUpdateRequest request) {
        return userProfileServiceI.updateUserAvatar(getUserContext(), request);
    }

    @PostMapping("/user-profile/upload-nickname")
    public UserProfileUpdateResponse saveNickName(@RequestBody UserProfileUpdateRequest request) {
        return userProfileServiceI.updateUserNickName(getUserContext(), request);
    }
}
