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

import com.neusoft.smart.pos.dto.promotion.bean.CalculateBean;
import com.neusoft.smart.pos.dto.promotion.request.GetPreferentialPriceRequest;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.member.dto.BonusCalculatorTypeResponse;
import com.neusoft.smart.pos.member.dto.MemberLevelConditionTypeResponse;
import com.neusoft.smart.pos.member.dto.MemberLevelPolicyResponse;
import com.neusoft.smart.pos.member.dto.request.*;
import com.neusoft.smart.pos.member.service.MemberLevelPolicyService;
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.*;

import java.util.List;

@Api(value = "会员等级管理restful接口", description = "会员等级管理restful接口")
@RestController
@Validated
public class MemberLevelPolicyController {
    @Autowired
    private MemberLevelPolicyService memberLevelPolicyService;

    @ApiOperation(value = "get member level condition types")
    @GetMapping("/member-level-policy/condition-types")
    public ResponseData<List<MemberLevelConditionTypeResponse>> getMemberLevelPolicyConditionTypes() {
        return new ResponseData<>(memberLevelPolicyService.getMemberLevelPolicyConditionTypes());
    }

    @ApiOperation(value = "get member level bonus calculator types")
    @GetMapping("/member-level-policy/calculator-types")
    public ResponseData<List<BonusCalculatorTypeResponse>> getBonusCalculatorTypes() {
        return new ResponseData<>(memberLevelPolicyService.getBonusCalculatorTypes());
    }

    @ApiOperation(value = "get member level list")
    @GetMapping("/member-level-policy")
    public ResponseData<List<MemberLevelPolicyResponse>> getMemberLevelPolicyList(@Validated @ModelAttribute GetMemberLevelPolicyRequest request) {
        return new ResponseData<>(memberLevelPolicyService.selectMemberLevelPolicyList(request));
    }

    @ApiOperation(value = "get member level")
    @GetMapping("/member-level-policy/{id}")
    public ResponseData<MemberLevelPolicyResponse> getMemberLevelPolicy(@PathVariable Integer id) {
        return new ResponseData<>(memberLevelPolicyService.selectMemberLevelPolicyById(id));
    }

    @ApiOperation(value = "create member level")
    @PostMapping("/member-level-policy")
    public ResponseData<MemberLevelPolicyResponse> createMemberLevelPolicy(@RequestBody CreateMemberLevelPolicyRequest request) {
        return new ResponseData<>(memberLevelPolicyService.insertOrUpdateMemberLevelPolicy(request));
    }

    @ApiOperation(value = "update member level")
    @PatchMapping("/member-level-policy/{id}")
    public ResponseData<MemberLevelPolicyResponse> updateMemberLevelPolicy(@PathVariable Integer id, @RequestBody UpdateMemberLevelPolicyRequest request) {
        return new ResponseData<>(memberLevelPolicyService.updateMemberLevelPolicy(id, request));
    }

    @ApiOperation(value = "delete member level")
    @DeleteMapping("/member-level-policy")
    public ResponseData<Integer> deleteMemberLevelPolicy(@RequestBody DeleteMemberLevelPolicyRequest request) {
        memberLevelPolicyService.deleteMemberPolicyLevel(request);
        return new ResponseData<>(1);
    }
}

