package io.renren.modules.app.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.R;
import io.renren.modules.admin.entity.MemberEntity;
import io.renren.modules.admin.service.MemberService;
import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.form.TaxForm;

/**
 * 会员个人信息
 */
@RestController
@RequestMapping("/app/member")
public class AppMemberController {
    @Autowired
    private MemberService memberService;

    @Login
    @GetMapping("/info")
    public R userInfo(@RequestAttribute("userId") Integer userId) {
        Long mid = userId.longValue();
        
        MemberEntity member = memberService.getById(mid);

        return R.ok().put("member", member);
    }

    @Login
    @PostMapping("/taxsave")
    public R taxSave(@RequestAttribute("userId") Integer userId, TaxForm tax) {
        Long mid = userId.longValue();
        
        MemberEntity member = memberService.getById(mid);
        // MemberEntity member = new MemberEntity();
        member.setId(mid);
        member.setTaxType(tax.getTaxType());
        member.setTaxTitle(tax.getTaxTitle());
        member.setTaxNumber(tax.getTaxNumber());
        member.setCompanyAddress(tax.getCompanyAddress());
        member.setCompanyPhone(tax.getCompanyPhone());
        member.setBankAccount(tax.getBankAccount());
        member.setBankAccount(tax.getBankAccount());
        member.setMailingAddress(tax.getMailingAddress());
        member.setPostcode(tax.getPostcode());

        memberService.updateById(member);

        return R.ok();
    } 
}
