package com.ruoyi.dk.controller.app;

import com.ruoyi.dk.domain.Customer;
import com.ruoyi.dk.domain.CustomerInfo;
import com.ruoyi.dk.dto.admin.resp.CustomerAdminVO;
import com.ruoyi.dk.service.CustomerInfoService;
import com.ruoyi.dk.service.CustomerService;
import com.ruoyi.dk.service.HomeSettingService;
import com.ruoyi.component.core.domain.R;
import com.ruoyi.component.satoken.utils.LoginHelper;
import com.ruoyi.component.core.util.BeanConvertUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/customer")
@Tag(name = "客户接口")
public class AppCustomerController {

    @Autowired
    private CustomerInfoService customerInfoService;
    @Autowired
    private CustomerService customerService;
    @Autowired
    private HomeSettingService homeSettingService;

    @GetMapping("/info")
    @Operation(summary = "客户信息")
    public R<CustomerAdminVO> info(){
        Long customerId = LoginHelper.getUserId();
        Customer customer = customerService.getById(customerId);
        CustomerAdminVO customerAdminVO = BeanConvertUtil.convertTo(customer, CustomerAdminVO::new);
        customerAdminVO.setDefaultCoinUnit(homeSettingService.getHomeSetting().getDefaultCoinUnit());
        return R.ok(customerAdminVO);
    }

    @GetMapping("/card/info")
    @Operation(summary = "客户资料信息")
    public R<CustomerInfo> cardInfo(){
        Long customerId = LoginHelper.getUserId();
        CustomerInfo customerInfo = customerInfoService.getByCustomerId(customerId);
        return R.ok(customerInfo);
    }

    @PostMapping("/updateCustomerCard")
    @Operation(summary = "修改客户资料信息")
    public R<Void> updateCustomerCard(@RequestBody CustomerInfo customerInfo){
        Long customerId = LoginHelper.getUserId();
        customerInfo.setCustomerId(customerId);
        customerInfoService.updateCustomerInfo(customerInfo);
        return R.ok();
    }


}
