package com.xingxi.api.controller;

import com.xingxi.api.common.BaseApiController;
import com.xingxi.api.model.*;
import com.xingxi.api.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);
    }

    @PostMapping("/user-profile/address-list")
    public UserAddressListResponse getAddressList(@RequestBody UserAddressRequest request) {
        return userProfileServiceI.getUserAddressList(getUserContext(), request);
    }

    @PostMapping("/user-profile/save-address")
    public UserAddressListResponse saveAddress(@RequestBody UserAddressRequest request) {
        return userProfileServiceI.getUserAddressList(getUserContext(), request);
    }

}
