package com.neusoft.smart.pos.gateway.controller;

import com.neusoft.smart.pos.dto.member.request.CreateMemberRequest;
import com.neusoft.smart.pos.dto.member.request.GetSingleMemberRequest;
import com.neusoft.smart.pos.dto.member.request.PosRegisterMemberRequest;
import com.neusoft.smart.pos.dto.member.response.DetailedMemberResponse;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.gateway.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "pos端会员注册使用rest接口", description = "pos端会员注册使用rest接口")
@RestController
@RequestMapping(path = "/unionService/members")
@Validated
public class MemberController {
    @Autowired
    private MemberService memberService;

    @ApiOperation(value = "find member from pos")
    @GetMapping("/single/pos/{snCode}")
    public ResponseData<DetailedMemberResponse> getSingleMemberByPos(@PathVariable String snCode, GetSingleMemberRequest request) {
        //return memberService.findMemberByMobile(snCode, request.getMobile());
        return memberService.findMemberByRequest(snCode, request);
    }

    @ApiOperation(value = "register member from pos")
    @PostMapping("/pos/{snCode}")
    public ResponseData<DetailedMemberResponse> addMemberByPos(@PathVariable String snCode, @RequestBody PosRegisterMemberRequest request) {
        return memberService.registerMemberFromPos(snCode, request);
    }

    @ApiOperation(value = "create member")
    @PostMapping("/")
    public ResponseData<DetailedMemberResponse> addMember(@RequestBody CreateMemberRequest request) {
        return memberService.createMember(request);
    }
}
